local extension = Package:new("honor_room")
extension.extensionName = "wild_collection"
Fk:loadTranslationTable{
  ["honor"] = "“荣誉室”",
  ["honor_room"] = "“荣誉室”",
  ["honor_ol"] = "“荣誉室”",
  ["honor_olmou"] = "“荣誉室”",
  ["honor_olz"] = "“荣誉室”",
  ["honor_js"] = "“荣誉室”",
  ["honor_js2"] = "“荣誉室”",
  ["honor_mou"] = "“荣誉室”",
  ["honor_ol_ex"] = "“荣誉室”",
}
local U = require "packages/utility/utility"

local zhonghui = General(extension, "honor_olz__zhonghui", "wei", 3, 4)
local yuzhi = fk.CreateTriggerSkill{
  name = "honor_yuzhi",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.RoundStart, fk.RoundEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.RoundStart then
        return not player:isKongcheng()
      else
        return player:usedSkillTimes(self.name, Player.HistoryRound) > 0
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name)
    if event == fk.RoundStart then
      room:notifySkillInvoked(player, self.name, "drawcard")
      local cards = room:askForCard(player, 1, 1, false, self.name, false, ".", "#yuzhi-card")
      local n = Fk:translate(Fk:getCardById(cards[1]).trueName, "zh_CN"):len()
      room:setCardMark(Fk:getCardById(cards[1]), "@@yuzhi-inhand-round", 1)
      player:showCards(cards)
      if player.dead then return false end
      room:drawCards(player, n, self.name)
      if player.dead then return false end
      room:setPlayerMark(player, "@yuzhi-round", n)
    else
      room:notifySkillInvoked(player, self.name, "negative")
      --牢会回归
      --[[local card
      local cards = table.filter(player:getCardIds(Player.Hand), function (id)
        card = Fk:getCardById(id)
        return card:getMark("@@yuzhi-inhand-round") > 0 and not player:prohibitDiscard(card)
      end)
      if #cards > 0 then
        room:throwCard(cards, self.name, player, player)
        if player.dead then return false end
      end]]
      local x = player:getMark("@yuzhi-round")
      if x == 0 then return false end
      if room:getTag("RoundCount") == 1 or player:getMark("_yuzhi-round") >= x then
        local round_event = room.logic:getCurrentEvent():findParent(GameEvent.Round, true)
        if round_event == nil then return false end
        local use_events = room.logic:getEventsByRule(GameEvent.UseCard, x, function(e)
          return e.data[1].from == player.id
        end, round_event.id)
        if #use_events >= x then return false end
      end
      if player:hasSkill(baozu, true) and room:askForChoice(player, {"yuzhi1", "yuzhi2"}, self.name) == "yuzhi2" then
        room:handleAddLoseSkills(player, "-baozu", nil, true, false)
      else
        room:loseHp(player, 1, self.name)
      end
    end
  end,

  refresh_events = {fk.RoundEnd},
  can_refresh = Util.TrueFunc,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if player:getMark("_yuzhi-round") ~= player:getMark("_yuzhi_tmp") then
      room:setPlayerMark(player, "_yuzhi-round", player:getMark("_yuzhi_tmp"))
    end
    if player:getMark("@yuzhi-round") ~= player:getMark("_yuzhi_tmp") then
      room:setPlayerMark(player, "_yuzhi_tmp", player:getMark("@yuzhi-round"))
    end
  end,
}
local xieshu = fk.CreateTriggerSkill{
  name = "honor_xieshu",
  anim_type = "drawcard",
  events = {fk.Damage, fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, data,
    "#xieshu-invoke:::"..tostring(Fk:translate(data.card.trueName, "zh_CN"):len())..":"..player:getLostHp())
  end,
  on_use = function(self, event, target, player, data)
    if player.dead then return false end
    local room = player.room
    local n = Fk:translate(data.card.trueName, "zh_CN"):len()
    local cards = room:askForDiscard(player, n, n, true, self.name, false, ".", nil, true)
    if #cards < n then return false end
    room:throwCard(cards, self.name, player, player)
    if not player.dead and player:isWounded() then
      player:drawCards(player:getLostHp(), self.name)
      --[[if player.dead then return false end
      local logic = room.logic
      local turn_event = logic:getCurrentEvent():findParent(GameEvent.Turn)
      if turn_event == nil then return false end
      local dying_events = logic.event_recorder[GameEvent.Dying] or Util.DummyTable
      if #dying_events > 0 and dying_events[#dying_events].id > turn_event.id then
        room:invalidateSkill(player, self.name, "-turn")
      end]]
    end
  end,
}
zhonghui:addSkill(yuzhi)
zhonghui:addSkill(xieshu)
zhonghui:addSkill("baozu")
Fk:loadTranslationTable{
  ["honor_olz__zhonghui"] = "族钟会",
  ["#honor_olz__zhonghui"] = "百巧惎",
  ["designer:honor_olz__zhonghui"] = "玄蝶既白",
  ["illustrator:honor_olz__zhonghui"] = "黯荧岛",
  ["honor_yuzhi"] = "迂志",
  [":honor_yuzhi"] = "锁定技，每轮开始时，你展示一张手牌，摸X张牌。此轮结束时，若你于此轮内使用过的牌数或上轮以此法摸牌数小于X，"..
  "你失去1点体力或失去〖保族〗。（X为此牌牌名字数）",
  ["honor_xieshu"] = "挟术",
  [":honor_xieshu"] = "当你造成或受到牌的伤害后，你可以弃置X张牌（X为此牌牌名字数）并摸你已损失体力值张数的牌。",
  ["#yuzhi-card"] = "迂志：展示一张手牌，摸其牌名字数的牌",
  ["@@yuzhi-inhand-round"] = "迂志",
  ["@yuzhi-round"] = "迂志",
  ["yuzhi1"] = "失去1点体力",
  ["yuzhi2"] = "失去〖保族〗",
  [":loseHp"] = "失去1点体力",
  ["#xieshu-invoke"] = "是否发动 挟术，弃置%arg张牌并摸%arg2张牌",

  ["$honor_yuzhi1"] = "我欲行夏禹旧事，为天下人。",
  ["$honor_yuzhi2"] = "汉鹿已失，魏牛犹在，吾欲执其耳。",
  ["$honor_xieshu1"] = "今长缨在手，欲问鼎九州。",
  ["$honor_xieshu2"] = "我有佐国之术，可缚苍龙。",
  ["$baozu_honor_olz__zhonghui1"] = "不为刀下脍，且做俎上刀。",
  ["$baozu_honor_olz__zhonghui2"] = "吾族恒大，谁敢欺之？",
  ["~honor_olz__zhonghui"] = "谋事在人，成事在天……",
}

local pengyang = General(extension, "honor_ol__pengyang", "shu", 3)
local xiaofan = fk.CreateViewAsSkill{
  name = "honor_xiaofan",
  pattern = ".",
  anim_type = "special",
  expand_pile = function (self)
    return table.slice(Self:getTableMark("xiaofan_view"), 1, #Self:getTableMark("xiaofan_types") + 2)
  end,
  prompt = function()
    return "#xiaofan:::"..(#Self:getTableMark("xiaofan_types") + 1)
  end,
  card_filter = function(self, to_select, selected)
    if #selected == 0 and table.contains(Self:getTableMark("xiaofan_view"), to_select) then
      local card = Fk:getCardById(to_select)
      if Fk.currentResponsePattern == nil then
        return Self:canUse(card) and not Self:prohibitUse(card)
      else
        return Exppattern:Parse(Fk.currentResponsePattern):match(card)
      end
    end
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return end
    local c = Fk:getCardById(cards[1])
    c.skillName = self.name
    return c
  end,
  after_use = function (self, player, useData)
    local x = #player:getTableMark("xiaofan_types")
    local areas = {"j", "e", "h"}
    local to_throw = ""
    for i = 1, x, 1 do
      to_throw = to_throw .. areas[i]
    end
    player:throwAllCards(to_throw)
  end,
  enabled_at_play = function(self, player)
    return #player:getTableMark("xiaofan_view") > 0
  end,
  enabled_at_response = function(self, player, response)
    return not response and #player:getTableMark("xiaofan_view") > 0
  end,
}
local xiaofan_trigger = fk.CreateTriggerSkill{
  name = "#honor_xiaofan_trigger",
  mute = true,

  refresh_events = {fk.AfterCardsMove, fk.AfterDrawPileShuffle, fk.PreCardUse, fk.EventAcquireSkill, fk.EventLoseSkill},
  can_refresh = function(self, event, target, player, data)
    if event == fk.EventAcquireSkill or event == fk.EventLoseSkill then
      return data == xiaofan
    elseif event == fk.PreCardUse then
      return player == target and table.contains(data.card.skillNames or {}, xiaofan.name)
    else
      return player:hasSkill(xiaofan, true)
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardsMove or event == fk.AfterDrawPileShuffle then
      local mark = player:getTableMark("xiaofan_view")
      local draw_pile = room.draw_pile
      local new_mark = {}
      for i = 0, 3, 1 do
        if #draw_pile <= i then break end
        table.insert(new_mark, draw_pile[#draw_pile - i])
      end
      if #new_mark ~= mark then
        room:setPlayerMark(player, "xiaofan_view", new_mark)
      end
      for i = 1, #new_mark, 1 do
        if new_mark[i] ~= new_mark[i] then
          room:setPlayerMark(player, "xiaofan_view", new_mark)
          return false
        end
      end
    elseif event == fk.PreCardUse then
      local mark = player:getTableMark("xiaofan_types")
      local type_name = data.card:getTypeString()
      if not table.contains(mark, type_name) then
        table.insert(mark, type_name)
        room:setPlayerMark(player, "xiaofan_types", mark)
      end
    elseif event == fk.EventAcquireSkill then
      local draw_pile = room.draw_pile
      local mark = {}
      for i = 0, 2, 1 do
        if #draw_pile <= i then break end
        table.insert(mark, draw_pile[#draw_pile - i])
      end
      room:setPlayerMark(player, "xiaofan_view", mark)

      local mark = player:getTableMark("xiaofan_types")
      local current_event = room.logic:getCurrentEvent()
      if current_event == nil then return false end
      local start_event = current_event:findParent(GameEvent.Turn, true)
      if start_event == nil then return false end
      room.logic:getEventsOfScope(GameEvent.UseCard, 1, function (e)
        local use = e.data[1]
        if use.from == player.id then
          table.insertIfNeed(mark, use.card:getTypeString())
        end
        return #mark == 3
      end, Player.HistoryTurn)
      room:setPlayerMark(player, "xiaofan_types", mark)
    elseif event == fk.EventLoseSkill then
      room:setPlayerMark(player, "xiaofan_view", 0)
    end
  end,
}
local tuoshi = fk.CreateTriggerSkill{
  name = "honor_tuoshi",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.CardUsing},
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(self) and (data.card.number == 1 or data.card.number > 10)
  end,
  on_use = function (self, event, target, player, data)
    player:drawCards(2, self.name)
    player.room:setPlayerMark(player, "@@tuoshi", 1)
  end,

  refresh_events = {fk.PreCardUse},
  can_refresh = function (self, event, target, player, data)
    if player ~= target or player:getMark("@@tuoshi") == 0 then return false end
    local room = player.room
    return table.find(TargetGroup:getRealTargets(data.tos), function (pid)
      return room:getPlayerById(pid):getHandcardNum() < player:getHandcardNum()
    end)
  end,
  on_refresh = function (self, event, target, player, data)
    data.extraUse = true
    player.room:setPlayerMark(player, "@@tuoshi", 0)
  end,
}
local tuoshi_prohibit = fk.CreateProhibitSkill{
  name = "#honor_tuoshi_prohibit",
  frequency = Skill.Compulsory,
  prohibit_use = function(self, player, card)
    return player:hasSkill(tuoshi) and card and card.trueName == "nullification"
  end,
}
local tuoshi_targetmod = fk.CreateTargetModSkill{
  name = "#honor_tuoshi_targetmod",
  bypass_times = function(self, player, skill, scope, card, to)
    return player:getMark("@@tuoshi") > 0
  end,
  bypass_distances =  function(self, player, skill, card, to)
    return player:getMark("@@tuoshi") > 0
  end,
}
xiaofan:addRelatedSkill(xiaofan_trigger)
tuoshi:addRelatedSkill(tuoshi_prohibit)
tuoshi:addRelatedSkill(tuoshi_targetmod)
pengyang:addSkill(xiaofan)
pengyang:addSkill(tuoshi)
pengyang:addSkill("cunmu")

Fk:loadTranslationTable{
  ["honor_ol__pengyang"] = "彭羕",
  ["#honor_ol__pengyang"] = "翻然轻举",
  ["illustrator:honor_ol__pengyang"] = "佚名",
  ["designer:honor_ol__pengyang"] = "玄蝶既白",
  ["honor_xiaofan"] = "嚣翻",
  [":honor_xiaofan"] = "当你需要使用牌时，你可以观看牌堆底X+1张牌，然后可以使用其中你需要的牌并弃置你前X区域里的牌："..
  "1.判定区；2.装备区；3.手牌区。（X为你以此法使用过牌的类别数）",
  ["honor_tuoshi"] = "侻失",
  [":honor_tuoshi"] = "锁定技，你不能使用【无懈可击】。"..
  "你使用点数为字母的牌时，你摸两张牌，且下次使用牌无距离和次数限制。",
  ["@@tuoshi"] = "侻失",

  ["$honor_xiaofan1"] = "吾得三顾之伯乐，必登九丈之高台。",
  ["$honor_xiaofan2"] = "诸君食肉而鄙夷，空有大腹作碍。",
  ["$honor_tuoshi1"] = "备者，久居行伍之丘八，何知礼仪？",
  ["$honor_tuoshi2"] = "老革荒悖，可复道邪？",
  ["$cunmu_honor_ol__pengyang1"] = "腹有锦绣千里，奈何偏居一隅。",
  ["$cunmu_honor_ol__pengyang2"] = "心大志广之人，必难以保安。",
  ["~honor_ol__pengyang"] = "羕酒后失言，主公勿怪。",
}

local moucaopi = General(extension, "honor_mou__caopi", "wei", 3)
Fk:loadTranslationTable{
  ["honor_mou__caopi"] = "谋曹丕",
  ["#honor_mou__caopi"] = "魏文帝",
  ["~honor_mou__caopi"] = "大魏如何踏破吴蜀，就全看叡儿了……",
}

local mouxingshang = fk.CreateActiveSkill{
  name = "honor_mou__xingshang",
  anim_type = "support",
  prompt = "#honor_mou__xingshang",
  card_num = 0,
  target_num = 1,
  interaction = function(self)
    local choiceList = {
      "honor_mou__xingshang_restore",
      "honor_mou__xingshang_draw",
      "honor_mou__xingshang_recover",
      "honor_mou__xingshang_memorialize",
    }
    local choices = {}
    local markValue = Self:getMark("@honor_mou__xingshang_song")
    if markValue > 1 then
      table.insertTable(choices, { choiceList[1], choiceList[2] })
    end
    if markValue > 4 then
      table.insert(choices, choiceList[3])
    end
    if markValue > 4 then
      if
        table.find(
          Fk:currentRoom().players,
          function(p)
            return p.dead and p.rest < 1 and not table.contains(Fk:currentRoom():getBanner('memorializedPlayers') or {}, p.id)
          end
        )
      then
        local skills = Fk.generals[Self.general]:getSkillNameList()
        if Self.deputyGeneral ~= "" then
          table.insertTableIfNeed(skills, Fk.generals[Self.deputyGeneral]:getSkillNameList())
        end

        if table.find(skills, function(skillName) return skillName == self.name end) then
          table.insert(choices, "honor_mou__xingshang_memorialize")
        end
      end
    end

    return UI.ComboBox { choices = choices, all_choices = choiceList }
  end,
  times = function(self)
    return Self.phase == Player.Play and 2 - Self:getMark("honor_mou__xingshang_used-phase") or -1
  end,
  can_use = function(self, player)
    return player:getMark("honor_mou__xingshang_used-phase") < 2 and player:getMark("@honor_mou__xingshang_song") > 1
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    if #selected > 0 then
      return false
    end

    local interactionData = self.interaction.data
    if interactionData == "honor_mou__xingshang_recover" then
      return Fk:currentRoom():getPlayerById(to_select).maxHp < 10
    elseif interactionData == "honor_mou__xingshang_memorialize" then
      return to_select == Self.id
    end

    return true
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:addPlayerMark(player, "honor_mou__xingshang_used-phase")

    local choice = self.interaction.data
    if choice == "honor_mou__xingshang_restore" then
      room:removePlayerMark(player, "@honor_mou__xingshang_song", 2)
      target:reset()
    elseif choice:startsWith("honor_mou__xingshang_draw") then
      room:removePlayerMark(player, "@honor_mou__xingshang_song", 2)
      target:drawCards(3, self.name)
    elseif choice == "honor_mou__xingshang_recover" then
      room:removePlayerMark(player, "@honor_mou__xingshang_song", 5)
      room:recover({
        who = target,
        num = 1,
        recoverBy = player,
        skillName = self.name,
      })
      if target.dead then return end
      room:changeMaxHp(target, 1)

      if not target.dead and #target.sealedSlots > 0 then
        room:resumePlayerArea(target, {table.random(target.sealedSlots)})
      end
    elseif choice == "honor_mou__xingshang_memorialize" then
      room:removePlayerMark(player, "@honor_mou__xingshang_song", 5)
      local zhuisiPlayers = room:getBanner('memorializedPlayers') or {}
      table.insertIfNeed(zhuisiPlayers, target.id)
      room:setBanner('memorializedPlayers', zhuisiPlayers)

      local availablePlayers = table.map(table.filter(room.players, function(p)
        return not p:isAlive() and p.rest < 1 and not table.contains(room:getBanner('memorializedPlayers') or {}, p.id)
      end), Util.IdMapper)
      local toId
      local result = room:askForCustomDialog(
        target, self.name,
        "packages/mougong/qml/ZhuiSiBox.qml",
        { availablePlayers, "$MouXingShang" }
      )

      if result == "" then
        toId = table.random(availablePlayers)
      else
        toId = json.decode(result).playerId
      end

      local to = room:getPlayerById(toId)
      local skills = Fk.generals[to.general]:getSkillNameList()
      if to.deputyGeneral ~= "" then
        table.insertTableIfNeed(skills, Fk.generals[to.deputyGeneral]:getSkillNameList())
      end
      skills = table.filter(skills, function(skill_name)
        local skill = Fk.skills[skill_name]
        return not skill.lordSkill and not (#skill.attachedKingdom > 0 and not table.contains(skill.attachedKingdom, target.kingdom))
      end)
      if #skills > 0 then
        room:handleAddLoseSkills(target, table.concat(skills, "|"))
      end

      room:setPlayerMark(target, "@honor_mou__xingshang_memorialized", to.deputyGeneral ~= "" and "seat#" .. to.seat or to.general)
      room:handleAddLoseSkills(player, "-" .. self.name .. '|-mou__fangzhu|-mou__songwei')
    end
  end,

  on_lose = function (self, player)
    local room = player.room
    room:setPlayerMark(player, "honor_mou__xingshang_used-phase", 0)
    room:setPlayerMark(player, "honor_mou__xingshang_damaged-turn", 0)
    room:setPlayerMark(player, "@honor_mou__xingshang_song", 0)
  end
}
local mouxingshangTriggger = fk.CreateTriggerSkill{
  name = "#honor_mou__xingshang_trigger",
  mute = true,
  main_skill = mouxingshang,
  events = {fk.Damaged, fk.Death},
  can_trigger = function(self, event, target, player, data)
    return
      player:hasSkill(mouxingshang) and
      player:getMark("@honor_mou__xingshang_song") < 9 and
      (event ~= fk.Damaged or (player:getMark("honor_mou__xingshang_damaged-turn") == 0 and data.to:isAlive()))
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.Damaged then
      room:setPlayerMark(player, "honor_mou__xingshang_damaged-turn", 1)
    end

    room:addPlayerMark(player, "@honor_mou__xingshang_song", math.min(2, 9 - player:getMark("@honor_mou__xingshang_song")))
  end,
}
Fk:loadTranslationTable{
  ["honor_mou__xingshang"] = "行殇",
  [":honor_mou__xingshang"] = "当一名角色受到伤害后（每回合限一次）或死亡时，则你获得两枚“颂”标记（你至多拥有9枚“颂”标记）；" ..
  "出牌阶段限两次，你可选择一名角色并移去至少一枚“颂”令其执行对应操作：2枚，复原武将牌或摸三张牌；" ..
  "5枚，回复1点体力并加1点体力上限，然后随机恢复一个已废除的装备栏（目标体力上限不大于9方可选择）；" ..
  "5枚，<a href='memorialize'>追思</a>一名已阵亡的角色（你选择自己且你的武将牌上有〖行殇〗时方可选择此项），"..
  "获得其武将牌上除主公技外的所有技能，然后你失去〖行殇〗、〖放逐〗、〖颂威〗。",

  ["memorialize"] = "#\"<b>追思</b>\"：被追思过的角色本局游戏不能再成为追思的目标。",
  ["#honor_mou__xingshang"] = "放逐：你可选择一名角色，消耗一定数量的“颂”标记对其进行增益",
  ["#honor_mou__xingshang_trigger"] = "行殇",
  ["$MouXingShang"] = "行殇",
  ["@honor_mou__xingshang_song"] = "颂",
  ["@honor_mou__xingshang_memorialized"] = "行殇",
  ["honor_mou__xingshang_restore"] = "2枚：复原武将牌",
  ["honor_mou__xingshang_draw"] = "2枚：摸三张牌",
  ["honor_mou__xingshang_recover"] = "5枚：恢复体力与区域",
  ["honor_mou__xingshang_memorialize"] = "5枚：追思技能",

  ["$honor_mou__xingshang1"] = "纵是身死，仍要为我所用。",
  ["$honor_mou__xingshang2"] = "汝九泉之下，定会感朕之情。",
}

mouxingshang:addRelatedSkill(mouxingshangTriggger)
moucaopi:addSkill(mouxingshang)

local moufangzhu = fk.CreateActiveSkill{
  name = "honor_mou__fangzhu",
  anim_type = "control",
  prompt = "#honor_mou__fangzhu",
  card_num = 0,
  target_num = 1,
  interaction = function(self)
    local choiceList = {
      "honor_mou__fangzhu_only_basic",
      "honor_mou__fangzhu_only_trick",
      "honor_mou__fangzhu_only_equip",
      "honor_mou__fangzhu_nullify_skill",
      "honor_mou__fangzhu_disresponsable",
      "honor_mou__fangzhu_turn_over",
    }
    local choices = {"honor_mou__fangzhu_only_basic"}
    local x = Self:getMark("@honor_mou__xingshang_song")
    if x > 1 then
      table.insert(choices, "honor_mou__fangzhu_disresponsable")
      table.insert(choices, "honor_mou__fangzhu_only_trick")
      if not Fk:currentRoom():isGameMode("1v2_mode") then
        table.insert(choices, "honor_mou__fangzhu_nullify_skill")
        if x > 2 then
          table.insert(choices, "honor_mou__fangzhu_only_equip")
          table.insert(choices, "honor_mou__fangzhu_turn_over")
        end
      end
    end
    return UI.ComboBox { choices = choices, all_choices = choiceList }
  end,
  can_use = function(self, player)
    return
      player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and
      player:getMark("@honor_mou__xingshang_song") > 0 and
      player:hasSkill(mouxingshang, true)
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= Self.id
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])

    local choice = self.interaction.data
    if choice:startsWith("honor_mou__fangzhu_only") then
      choice = choice:sub(-5)
      room:removePlayerMark(player, "@honor_mou__xingshang_song", choice == "basic" and 1 or (choice == "trick" and 2 or 3))
      local limit_mark = target:getTableMark("@honor_mou__fangzhu_limit")
      table.insertIfNeed(limit_mark, choice.."_char")
      room:setPlayerMark(target, "@honor_mou__fangzhu_limit", limit_mark)
    elseif choice == "honor_mou__fangzhu_nullify_skill" then
      room:removePlayerMark(player, "@honor_mou__xingshang_song", 2)
      room:setPlayerMark(target, "@@mou__fangzhu_skill_nullified", 1)
    elseif choice == "honor_mou__fangzhu_disresponsable" then
      room:removePlayerMark(player, "@honor_mou__xingshang_song", 2)
      room:setPlayerMark(target, "@@mou__fangzhu_disresponsable", 1)
    elseif choice == "honor_mou__fangzhu_turn_over" then
      room:removePlayerMark(player, "@honor_mou__xingshang_song", 3)
      target:turnOver()
    end
  end,
}
local moufangzhuRefresh = fk.CreateTriggerSkill{
  name = "#honor_mou__fangzhu_refresh",
  refresh_events = { fk.AfterTurnEnd, fk.CardUsing },
  can_refresh = function(self, event, target, player, data)
    if event == fk.AfterTurnEnd then
      return
        target == player and
        table.find(
          { "@honor_mou__fangzhu_limit", "@@mou__fangzhu_skill_nullified", "@@mou__fangzhu_disresponsable" },
          function(markName) return player:getMark(markName) ~= 0 end
        )
    end

    return
      target == player and
      table.find(
        player.room.alive_players,
        function(p) return p:getMark("@@mou__fangzhu_disresponsable") > 0 and p ~= target end
      )
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room

    if event == fk.AfterTurnEnd then
      for _, markName in ipairs({ "@honor_mou__fangzhu_limit", "@@mou__fangzhu_skill_nullified", "@@mou__fangzhu_disresponsable" }) do
        if player:getMark(markName) ~= 0 then
          room:setPlayerMark(player, markName, 0)
        end
      end
    else
      data.disresponsiveList = data.disresponsiveList or {}
      local tos = table.filter(
        player.room.alive_players,
        function(p) return p:getMark("@@mou__fangzhu_disresponsable") > 0 and p ~= target end
      )
      table.insertTableIfNeed(data.disresponsiveList, table.map(tos, Util.IdMapper))
    end
  end,
}
local moufangzhuProhibit = fk.CreateProhibitSkill{
  name = "#honor_mou__fangzhu_prohibit",
  prohibit_use = function(self, player, card)
    local typeLimited = player:getMark("@honor_mou__fangzhu_limit")
    if typeLimited == 0 then return false end
    if table.every(Card:getIdList(card), function(id)
      return table.contains(player:getCardIds(Player.Hand), id)
    end) then
      return #typeLimited > 1 or typeLimited[1] ~= card:getTypeString() .. "_char"
    end
  end,
}
local moufangzhuNullify = fk.CreateInvaliditySkill {
  name = "#honor_mou__fangzhu_nullify",
  invalidity_func = function(self, from, skill)
    return from:getMark("@@mou__fangzhu_skill_nullified") > 0 and skill:isPlayerSkill(from)
  end
}
Fk:loadTranslationTable{
  ["honor_mou__fangzhu"] = "放逐",
  [":honor_mou__fangzhu"] = "出牌阶段限一次，若你有〖行殇〗，则你可以选择一名其他角色，并移去至少一枚“颂”标记令其执行对应操作：" ..
  "1枚，直到其下个回合结束，其不能使用除基本牌外的手牌；2枚，直到其下个回合结束，其不可响应除其外的角色使用的牌，" ..
  "2枚，直到其下个回合结束，其所有武将技能失效，或其不能使用除锦囊牌外的手牌；3枚，其翻面，或直到其下个回合结束，其不能使用除装备牌外的手牌"..
  "（若为斗地主，则令其他角色技能失效、只可使用装备牌及翻面的效果不可选择）。",
  ["#honor_mou__fangzhu"] = "放逐：你可选择一名角色，消耗一定数量的“颂”标记对其进行限制",
  ["#honor_mou__fangzhu_prohibit"] = "放逐",
  ["@honor_mou__fangzhu_limit"] = "放逐限",
  ["@@mou__fangzhu_skill_nullified"] = "放逐 技能失效",
  ["@@mou__fangzhu_disresponsable"] = "放逐 不可响应",
  ["honor_mou__fangzhu_only_basic"] = "1枚：只可使用基本牌",
  ["honor_mou__fangzhu_only_trick"] = "2枚：只可使用锦囊牌",
  ["honor_mou__fangzhu_only_equip"] = "3枚：只可使用装备牌",
  ["honor_mou__fangzhu_nullify_skill"] = "2枚：武将技能失效",
  ["honor_mou__fangzhu_disresponsable"] = "2枚：不可响应他人牌",
  ["honor_mou__fangzhu_turn_over"] = "3枚：翻面",

  ["$honor_mou__fangzhu1"] = "战败而降，辱我国威，岂能轻饶！",
  ["$honor_mou__fangzhu2"] = "此等过错，不杀已是承了朕恩。",
}

moufangzhu:addRelatedSkill(moufangzhuRefresh)
moufangzhu:addRelatedSkill(moufangzhuProhibit)
moufangzhu:addRelatedSkill(moufangzhuNullify)
moucaopi:addSkill(moufangzhu)

local mousongwei = fk.CreateActiveSkill{
  name = "honor_mou__songwei$",
  anim_type = "control",
  prompt = "#honor_mou__songwei",
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return
      player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and
      table.find(Fk:currentRoom().alive_players, function(p) return p.kingdom == "wei" end)
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= Self.id and Fk:currentRoom():getPlayerById(to_select).kingdom == "wei"
  end,
  on_use = function(self, room, effect)
    local target = room:getPlayerById(effect.tos[1])
    local skills = Fk.generals[target.general]:getSkillNameList(true)
    if target.deputyGeneral ~= "" then
      table.insertTableIfNeed(skills, Fk.generals[target.deputyGeneral]:getSkillNameList(true))
    end
    if #skills > 0 then
      skills = table.map(skills, function(skillName) return "-" .. skillName end)
      room:handleAddLoseSkills(target, table.concat(skills, "|"), nil, true, false)
    end

    room:setPlayerMark(target, "@@mou__songwei_target", 1)
  end,
}

local mousongweiTrigger = fk.CreateTriggerSkill{
  name = "#honor_mou__songwei",
  events = { fk.EventPhaseStart },
  can_trigger = function(self, event, target, player, data)
    return
      target == player and
      player.phase == Player.Play and
      player:hasSkill(self) and
      player:hasSkill(mouxingshang, true) and
      player:getMark("@honor_mou__xingshang_song") < 9 and
      table.find(player.room.alive_players, function(p) return p.kingdom == "wei" and p ~= player end)
  end,
  on_trigger = function(self, event, target, player, data)
    local room = player.room
    local weiNum = #table.filter(room.alive_players, function(p) return p.kingdom == "wei" and p ~= player end)
    room:addPlayerMark(player, "@honor_mou__xingshang_song", math.min(weiNum * 2, 9 - player:getMark("@honor_mou__xingshang_song")))
  end,
}
Fk:loadTranslationTable{
  ["honor_mou__songwei"] = "颂威",
  [":honor_mou__songwei"] = "主公技，出牌阶段开始时，若你有〖行殇〗，你获得2X枚“颂”（X为其他魏势力游戏人数）。每局游戏限一次，出牌阶段，你可以令一名其他魏势力角色失去所有武将技能。",
  ["#honor_mou__songwei"] = "颂威：你可以让一名其他魏国角色失去技能",
  ["@@mou__songwei_target"] = "已颂威",

  ["$honor_mou__songwei1"] = "江山锦绣，尽在朕手。",
  ["$honor_mou__songwei2"] = "成功建业，扬我魏威。",
}

mousongwei:addRelatedSkill(mousongweiTrigger)
moucaopi:addSkill(mousongwei)

local dongzhuo = General(extension, "honor_olmou__dongzhuo", "qun", 5)
local guanbian = fk.CreateTriggerSkill{
  name = "honor_guanbian",
  events = {fk.GameStart},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  on_use = function(self, event, target, player)
    local room = player.room
    room:addPlayerMark(player, "@honor_guanbian-round", #room.players)
  end,

  refresh_events = {fk.RoundEnd, fk.AfterSkillEffect},
  can_refresh = function (self, event, target, player, data)
    if player:hasSkill(self, true) then
      if event == fk.RoundEnd then
        return true
      else
        return target == player and (data.name == "honor_xiongni" or data.name == "honor_fengshang")
      end
    end
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:handleAddLoseSkills(player, "-honor_guanbian", nil, true, false)
  end,

  on_lose = function (self, player)
    player.room:setPlayerMark(player, "@honor_guanbian-round", 0)
  end,
}
local guanbian_distance = fk.CreateDistanceSkill{
  name = "#honor_guanbian_distance",
  correct_func = function(self, from, to)
    return from:getMark("@honor_guanbian-round") + to:getMark("@honor_guanbian-round")
  end,
}
local guanbian_maxcards = fk.CreateMaxCardsSkill{
  name = "#honor_guanbian_maxcards",
  correct_func = function(self, player)
    return player:getMark("@honor_guanbian-round")
  end,
}
local xiongni = fk.CreateTriggerSkill{
  name = "honor_xiongni",
  anim_type = "offensive",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player.phase == Player.Play and player:hasSkill(self) and not player:isNude()
  end,
  on_cost = function (self, event, target, player, data)
    local card = player.room:askForDiscard(player, 1, 1, true, self.name, true, nil, "#honor_xiongni-invoke", true)
    if #card > 0 then
      self.cost_data = {cards = card}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, table.map(room:getOtherPlayers(player), Util.IdMapper))
    local suit = Fk:getCardById(self.cost_data.cards[1]):getSuitString()
    room:throwCard(self.cost_data.cards, self.name, player, player)
    for _, p in ipairs(room:getOtherPlayers(player)) do
      if not p.dead then
        if suit == "log_nosuit" or p:isNude() or
          #room:askForDiscard(p, 1, 1, true, self.name, true, ".|.|"..suit, "#honor_xiongni-discard:"..player.id.."::"..suit) == 0 then
          room:damage{
            from = player,
            to = p,
            damage = 1,
            skillName = self.name,
          }
        end
      end
    end
  end,
}
local fengshang = fk.CreateActiveSkill{
  name = "honor_fengshang",
  anim_type = "support",
  prompt = "#honor_fengshang",
  card_num = 0,
  target_num = 0,
  expand_pile = function()
    return Self:getTableMark("honor_fengshang")
  end,
  can_use = function(self, player)
    return player:getMark("honor_fengshang-phase") == 0 and
      table.find(player:getTableMark("honor_fengshang"), function (id)
        return table.find(player:getTableMark("honor_fengshang"), function (id2)
          return id ~= id2 and Fk:getCardById(id):compareSuitWith(Fk:getCardById(id2))
          --没有and，完全体形态！
           --[[and
            not table.contains(Self:getTableMark("honor_fengshang-round"), Fk:getCardById(id).suit)]]
        end)
      end)
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    --room:addPlayerMark(player, "honor_fengshang-phase", 1)
    local cards = {}
    room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function (e)
      for _, move in ipairs(e.data) do
        if move.toArea == Card.DiscardPile then
          for _, info in ipairs(move.moveInfo) do
            if table.contains(room.discard_pile, info.cardId) then
              table.insertIfNeed(cards, info.cardId)
            end
          end
        end
      end
    end, Player.HistoryTurn)
    cards = table.filter(cards, function (id)
      return table.find(cards, function (id2)
        return id ~= id2 and Fk:getCardById(id):compareSuitWith(Fk:getCardById(id2)) and
          not table.contains(player:getTableMark("honor_fengshang-round"), Fk:getCardById(id).suit)
      end)
    end)

    local targets = table.map(room.alive_players, Util.IdMapper)
    local toStr = function(int) return string.format("%d", int) end
    local residueMap = {}
    for _, pid in ipairs(targets) do
      residueMap[toStr(pid)] = 1
    end
    local data = {
      cards = cards,
      max_num = 1,
      targets = targets,
      residued_list = residueMap,
      expand_pile = cards,
    }

    local list = {}
    local success, dat = room:askForUseActiveSkill(player, "distribution_select_skill",
      "#honor_fengshang-choose", false, data, true)
    if success and dat then
      table.removeOne(targets, dat.targets[1])
      list[dat.targets[1]] = dat.cards
      room:setCardMark(Fk:getCardById(dat.cards[1]), "@DistributionTo", Fk:translate(room:getPlayerById(dat.targets[1]).general))
      room:addTableMark(player, "honor_fengshang-round", Fk:getCardById(dat.cards[1]).suit)
    end
    if #targets > 0 then
      local all_cards = table.filter(cards, function (c)
        return Fk:getCardById(c):compareSuitWith(Fk:getCardById(dat.cards[1]))
      end)
      cards = table.simpleClone(all_cards)
      table.removeOne(cards, dat.cards[1])
      data = {
        cards = cards,
        max_num = 1,
        targets = targets,
        residued_list = residueMap,
        expand_pile = all_cards,
      }
      success, dat = room:askForUseActiveSkill(player, "distribution_select_skill",
        "#honor_fengshang-choose", false, data, true)
      if success and dat then
        list[dat.targets[1]] = dat.cards
      end
    end
    for _, ids in pairs(list) do
      for _, id in ipairs(ids) do
        room:setCardMark(Fk:getCardById(id), "@DistributionTo", 0)
      end
    end
    room:doYiji(list, player.id, self.name)
    if not player.dead and not list[player.id] then
      local card = Fk:cloneCard("analeptic")
      card.skillName = self.name
      if not player:prohibitUse(Fk:cloneCard("analeptic")) and not player:isProhibited(player, Fk:cloneCard("analeptic")) then
        room:useCard({
          card = card,
          from = player.id,
          tos = {{player.id}},
          extra_data = {
            analepticRecover = player.dying
          },
          extraUse = true,
        })
      end
    end
  end,
}
local fengshang_trigger = fk.CreateTriggerSkill{
  name = "#honor_fengshang_trigger",
  events = {fk.EnterDying},
  mute = true,
  main_skill = fengshang,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(fengshang) then
      local cards = {}
      player.room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function (e)
        for _, move in ipairs(e.data) do
          if move.toArea == Card.DiscardPile then
            for _, info in ipairs(move.moveInfo) do
              if table.contains(player.room.discard_pile, info.cardId) then
                table.insertIfNeed(cards, info.cardId)
              end
            end
          end
        end
      end, Player.HistoryTurn)
      return table.find(cards, function (id)
        return table.find(cards, function (id2)
          return id ~= id2 and Fk:getCardById(id):compareSuitWith(Fk:getCardById(id2)) and
            not table.contains(player:getTableMark("honor_fengshang-round"), Fk:getCardById(id).suit)
        end)
      end)
    end
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#honor_fengshang")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("honor_fengshang")
    fengshang:onUse(room, {
      from = player.id,
      cards = {},
      tos = {},
    })
    room:removePlayerMark(player, "honor_fengshang-phase", 1)
  end,

  refresh_events = {fk.StartPlayCard},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(fengshang)
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local cards = {}
    room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function (e)
      for _, move in ipairs(e.data) do
        if move.toArea == Card.DiscardPile then
          for _, info in ipairs(move.moveInfo) do
            if table.contains(room.discard_pile, info.cardId) then
              table.insertIfNeed(cards, info.cardId)
            end
          end
        end
      end
    end, Player.HistoryTurn)
    room:setPlayerMark(player, "honor_fengshang", cards)
  end,
}
local zhibing = fk.CreateTriggerSkill{
  name = "honor_zhibing$",
  anim_type = "special",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and player.phase == Player.Start then
      if player:getMark("@honor_zhibing") > 2 and not table.contains(player:getTableMark(self.name), 1) then
        return true
      end
      if player:getMark("@honor_zhibing") > 5 and not table.contains(player:getTableMark(self.name), 2) then
        return not player:hasSkill("ty_ex__fencheng", true)
      end
      if player:getMark("@honor_zhibing") > 8 and not table.contains(player:getTableMark(self.name), 3) then
        return not player:hasSkill("benghuai", true)
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player:getMark("@honor_zhibing") > 2 and not table.contains(player:getTableMark(self.name), 1) then
      room:addTableMark(player, self.name, 1)
      room:changeMaxHp(player, 1)
      if not player.dead and player:isWounded() then
        room:recover{
          who = player,
          num = 1,
          recoverBy = player,
          skillName = self.name,
        }
      end
    end
    if player:getMark("@honor_zhibing") > 5 and not table.contains(player:getTableMark(self.name), 2) and
      not player:hasSkill("ty_ex__fencheng", true) then
      room:addTableMark(player, self.name, 2)
      room:handleAddLoseSkills(player, "ty_ex__fencheng", nil, true, false)
    end
    if player:getMark("@honor_zhibing") > 8 and not table.contains(player:getTableMark(self.name), 3) and
      not player:hasSkill("benghuai", true) then
      room:addTableMark(player, self.name, 3)
      room:handleAddLoseSkills(player, "benghuai", nil, true, false)
    end
    if #player:getTableMark(self.name) == 3 then
      room:setPlayerMark(player, "@honor_zhibing", 0)
    end
  end,

  --[[on_acquire = function (self, player)  --盲猜其实不会触发
    local room = player.room
    room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
      local use = e.data[1]
      if room:getPlayerById(use.from).kingdom == "qun" and use.card.color == Card.Black then
        room:addPlayerMark(player, "@zhibing", 1)
      end
    end, Player.HistoryGame)
  end,]]--

  on_lose = function (self, player)
    player.room:setPlayerMark(player, "@honor_zhibing", 0)
  end,

  refresh_events = {fk.AfterCardUseDeclared},
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(self, true) and target ~= player and
      target.kingdom == "qun" and data.card.color == Card.Black and
      table.find({1, 2, 3}, function (i)
        return not table.contains(player:getTableMark(self.name), i)
      end)
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:addPlayerMark(player, "@honor_zhibing", 1)
  end,
}
guanbian:addRelatedSkill(guanbian_distance)
guanbian:addRelatedSkill(guanbian_maxcards)
fengshang:addRelatedSkill(fengshang_trigger)
dongzhuo:addSkill(guanbian)
dongzhuo:addSkill(xiongni)
dongzhuo:addSkill(fengshang)
dongzhuo:addSkill(zhibing)
dongzhuo:addRelatedSkill("ty_ex__fencheng")
dongzhuo:addRelatedSkill("benghuai")
Fk:loadTranslationTable{
  ["honor_olmou__dongzhuo"] = "谋董卓",
  ["#honor_olmou__dongzhuo"] = "",
  ["illustrator:honor_olmou__dongzhuo"] = "",

  ["honor_guanbian"] = "观变",
  [":honor_guanbian"] = "锁定技，游戏开始时，你的手牌上限、其他角色与你的距离、你与其他角色的距离+X。首轮结束后或你发动〖凶逆〗或〖封赏〗后，"..
  "你失去此技能。（X为游戏人数）",
  ["honor_xiongni"] = "凶逆",
  [":honor_xiongni"] = "出牌阶段开始时，你可以弃置一张牌，所有其他角色需弃置一张与花色相同的牌，否则你对其造成1点伤害。",
  ["honor_fengshang"] = "封赏",
  [":honor_fengshang"] = "当一名角色进入濒死状态时，你可以将本回合弃牌堆中两张花色相同的牌分配给等量角色，"..
  "若你未以此法获得牌，你视为使用一张不计入次数的【酒】。",
  ["honor_zhibing"] = "执柄",
  [":honor_zhibing"] = "主公技，锁定技，准备阶段，若其他群雄势力角色累计使用黑色牌达到：3张，你加1点体力上限并回复1体力；6张，你获得〖焚城〗；"..
  "9张，你获得〖崩坏〗",
  ["@honor_guanbian-round"] = "观变",
  ["#honor_xiongni-invoke"] = "凶逆：你可以弃一张牌，所有其他角色选择弃一张相同花色的牌或你对其造成1点伤害",
  ["#honor_xiongni-discard"] = "凶逆：弃置一张%arg牌，否则 %src 对你造成1点伤害！",
  ["#honor_fengshang"] = "封赏：你可以将本回合弃牌堆中两张花色相同的牌分配给等量角色",
  ["#honor_fengshang-choose"] = "封赏：分配其中两张花色相同的牌",
  ["#honor_fengshang_trigger"] = "封赏",
  ["@honor_zhibing"] = "执柄",
}

local nanhualaoxian = General(extension, "honor_ol__nanhualaoxian", "qun", 4)
local hedao = fk.CreateTriggerSkill{
  name = "honor_hedao",
  anim_type = "special",
  frequency = Skill.Compulsory,
  events = {fk.AfterDying},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and player:getMark("honor_hedao_invoked") == 0 then
      local dying_events = player.room.logic:getEventsOfScope(GameEvent.Dying, 1, function(e)
        return e.data[1].who == player.id
      end, Player.HistoryGame)
      return #dying_events > 0 and dying_events[1].data[1] == data
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "honor_hedao_invoked", 1)
    room:setPlayerMark(player, "honor_tianshu_max", 2)
  end,

  on_acquire = function (self, player, is_start)  --避免和青书同时机询问
    if is_start and player:hasSkill(self) then
      player.room:setPlayerMark(player, "honor_tianshu_max", 1)
    end
  end,
}
local ol__shoushu = fk.CreateActiveSkill{
  name = "honor_ol__shoushu",
  anim_type = "support",
  card_num = 0,
  target_num = 1,
  prompt = "#honor_ol__shoushu",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and
      table.find(player:getTableMark("@[honor_tianshu]"), function (info)
        return player:usedSkillTimes(info.skillName, Player.HistoryGame) == 0
      end)
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= Self.id
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local skills = table.filter(player:getTableMark("@[honor_tianshu]"), function (info)
      return player:usedSkillTimes(info.skillName, Player.HistoryGame) == 0
    end)
    skills = table.map(skills, function (info)
      return info.skillName
    end)
    local args = {}
    for _, s in ipairs(skills) do
      local info = room:getBanner("honor_tianshu_skills")[s]
      table.insert(args, Fk:translate(":honor_tianshu_triggers"..info[1]).."，"..Fk:translate(":honor_tianshu_effects"..info[2]).."。")
    end
    local choice = room:askForChoice(player, args, self.name, "#honor_ol__shoushu-give::"..target.id)
    local skill = skills[table.indexOf(args, choice)]
    if #target:getTableMark("@[honor_tianshu]") > target:getMark("honor_tianshu_max") then
      skills = table.map(target:getTableMark("@[honor_tianshu]"), function (info)
        return info.skillName
      end)
      local to_throw = skills[1]
      if #skills > 1 then
        args = {}
        for _, s in ipairs(skills) do
          local info = room:getBanner("honor_tianshu_skills")[s]
          table.insert(args, Fk:translate(":honor_tianshu_triggers"..info[1]).."，"..Fk:translate(":honor_tianshu_effects"..info[2]).."。")
        end
        choice = room:askForChoice(target, args, self.name, "#honor_ol__shoushu-discard")
        to_throw = skills[table.indexOf(args, choice)]
      end
      room:handleAddLoseSkills(target, "-"..to_throw, nil, true, false)
      local banner = room:getBanner("honor_tianshu_skills")
      banner[to_throw] = nil
      room:setBanner("honor_tianshu_skills", banner)
    end
    room:handleAddLoseSkills(player, "-"..skill, nil, true, false)
    room:handleAddLoseSkills(target, skill, nil, true, false)
  end,
}
local qingshu = fk.CreateTriggerSkill{
  name = "honor_qingshu",
  anim_type = "special",
  frequency = Skill.Compulsory,
  events = {fk.GameStart, fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.GameStart then
        return true
      elseif event == fk.EventPhaseStart then
        return target == player and (player.phase == Player.Start or player.phase == Player.Finish)
      end
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    --初始化随机数
    math.randomseed(tonumber(tostring(os.time()):reverse():sub(1, 6)))

    --时机
    local nums = {}
    for i = 1, 30, 1 do
      table.insert(nums, i)
    end
    nums = table.random(nums, 3)
    local choices = {
      "honor_tianshu_triggers"..nums[1],
      "honor_tianshu_triggers"..nums[2],
      "honor_tianshu_triggers"..nums[3],
    }
    local choice_trigger = room:askForChoice(player, choices, self.name, "#honor_qingshu-choice_trigger", true)
    local trigger = tonumber(string.sub(choice_trigger, 17))

    --效果
    nums = {}
    for i = 1, 30, 1 do
      table.insert(nums, i)
    end
    --排除部分绑定时机效果
    if not table.contains({4, 7, 18, 21, 25, 29, 30}, trigger) then
      table.removeOne(nums, 5)  --获得造成伤害的牌
    end
    if not table.contains({8, 23}, trigger) then
      table.removeOne(nums, 13)  --令此牌对你无效
    end
    if not table.contains({12, 16}, trigger) then
      table.removeOne(nums, 15)  --改判
      table.removeOne(nums, 16)  --获得判定牌
    end
    if not table.contains({29, 30}, trigger) then
      table.removeOne(nums, 26)  --伤害+1
      table.removeOne(nums, 30)  --防止伤害
    end
    nums = table.random(nums, 3)
    choices = {
      "honor_tianshu_effects"..nums[1],
      "honor_tianshu_effects"..nums[2],
      "honor_tianshu_effects"..nums[3],
    }
    local choice_effect = room:askForChoice(player, choices, self.name,
      "#honor_qingshu-choice_effect:::"..Fk:translate(":"..choice_trigger), true)

    --若将超出上限则舍弃一个已有天书
    if #player:getTableMark("@[honor_tianshu]") > player:getMark("honor_tianshu_max") then
      local skills = table.map(player:getTableMark("@[honor_tianshu]"), function (info)
        return info.skillName
      end)
      local args = {}
      for _, s in ipairs(skills) do
        local info = room:getBanner("honor_tianshu_skills")[s]
        table.insert(args, Fk:translate(":honor_tianshu_triggers"..info[1]).."，"..Fk:translate(":honor_tianshu_effects"..info[2]).."。")
      end
      table.insert(args, "Cancel")
      local choice = room:askForChoice(player, args, self.name, "#honor_ol__shoushu-discard")
      if choice == "Cancel" then return false end
      local skill = skills[table.indexOf(args, choice)]
      room:handleAddLoseSkills(player, "-"..skill, nil, true, false)
      local banner = room:getBanner("honor_tianshu_skills")
      banner[skill] = nil
      room:setBanner("honor_tianshu_skills", banner)
    end

    --房间记录技能信息
    local banner = room:getBanner("honor_tianshu_skills") or {}
    local name = "honor_tianshu"
    for i = 1, 30, 1 do
      if banner["honor_tianshu"..tostring(i)] == nil then
        name = "honor_tianshu"..tostring(i)
        break
      end
    end
    banner[name] = {
      tonumber(string.sub(choice_trigger, 23)),
      tonumber(string.sub(choice_effect, 22)),
      player.id
    }
    room:setBanner("honor_tianshu_skills", banner)
    room:handleAddLoseSkills(player, name, nil, true, false)
  end,

  --几个持续一段时间的标记效果
  refresh_events = {fk.TurnStart, fk.AfterTurnEnd},
  can_refresh = function (self, event, target, player, data)
    if target == player then
      if event == fk.TurnStart then
        return player:getMark("@@honor_tianshu11") > 0
      elseif event == fk.AfterTurnEnd then
        return player:getMark("honor_tianshu20") > 0 or player:getMark("honor_tianshu24") ~= 0
      end
    end
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    if event == fk.TurnStart then
      room:removePlayerMark(player, MarkEnum.UncompulsoryInvalidity, player:getMark("@@honor_tianshu11"))
      room:setPlayerMark(player, "@@honor_tianshu11", 0)
    elseif event == fk.AfterTurnEnd then
      if player:getMark("honor_tianshu20") > 0 then
        room:removePlayerMark(player, MarkEnum.AddMaxCards, 2)
        room:removePlayerMark(player, "honor_tianshu20", 2)
      end
      room:setPlayerMark(player, "honor_tianshu24", 0)
    end
  end,
}
local tianshu_targetmod = fk.CreateTargetModSkill{  --姑且挂在青书上……
  name = "#honor_tianshu_targetmod",
  bypass_times = function(self, player, skill, scope, card, to)
    return card and table.contains(player:getTableMark("honor_tianshu24"), to.id)
  end,
  bypass_distances = function(self, player, skill, card, to)
    return card and table.contains(player:getTableMark("honor_tianshu24"), to.id)
  end,
}
qingshu:addRelatedSkill(tianshu_targetmod)
for loop = 1, 30, 1 do  --30个肯定够用
  local tianshu = fk.CreateTriggerSkill{
    name = "honor_tianshu"..loop,
    anim_type = "special",
    events = {fk.CardUseFinished, fk.EventPhaseStart, fk.Damaged, fk.Damage, fk.TargetConfirming,
      fk.EnterDying, fk.AfterCardsMove, fk.CardUsing, fk.CardResponding, fk.AskForRetrial, fk.CardEffectCancelledOut, fk.Deathed,
      fk.FinishJudge, fk.TargetConfirmed, fk.ChainStateChanged, fk.HpChanged, fk.RoundStart, fk.DamageCaused, fk.DamageInflicted},
    times = function (self)
      local room = Fk:currentRoom()
      local info = room:getBanner("honor_tianshu_skills")
      if info and info[self.name] and info[self.name][3] == Self.id then
        return 3 - Self:usedSkillTimes(self.name, Player.HistoryGame)
      else
        return 1 - Self:usedSkillTimes(self.name, Player.HistoryGame)
      end
    end,
    can_trigger = function(self, event, target, player, data)
      if player:hasSkill(self) then
        local room = player.room
        local info = room:getBanner("honor_tianshu_skills")[self.name][1]
        if info == 1 then
          return event == fk.CardUseFinished and target == player
        elseif info == 2 then
          return event == fk.CardUseFinished and target ~= player and data.tos and
            table.contains(TargetGroup:getRealTargets(data.tos), player.id)
        elseif info == 3 then
          return event == fk.EventPhaseStart and target == player and player.phase == Player.Play
        elseif info == 4 then
          return event == fk.Damaged and target == player
        elseif info == 5 then
          return event == fk.EventPhaseStart and target == player and player.phase == Player.Start
        elseif info == 6 then
          return event == fk.EventPhaseStart and target == player and player.phase == Player.Finish
        elseif info == 7 then
          return event == fk.Damage and target == player
        elseif info == 8 then
          return event == fk.TargetConfirming and target == player and data.card.trueName == "slash"
        elseif info == 9 then
          return event == fk.EnterDying
        elseif info == 10 then
          if event == fk.AfterCardsMove then
            for _, move in ipairs(data) do
              if move.from == player.id then
                for _, inf in ipairs(move.moveInfo) do
                  if inf.fromArea == Card.PlayerEquip then
                    return true
                  end
                end
              end
            end
          end
        elseif info == 11 then
          return (event == fk.CardUsing or event == fk.CardResponding) and target == player and data.card.trueName == "jink"
        elseif info == 12 then
          return event == fk.AskForRetrial and data.card
        elseif info == 13 then
          if event == fk.AfterCardsMove then
            for _, move in ipairs(data) do
              if move.from == player.id then
                for _, inf in ipairs(move.moveInfo) do
                  if inf.fromArea == Card.PlayerHand then
                    return true
                  end
                end
              end
            end
          end
        elseif info == 14 then
          return event == fk.CardEffectCancelledOut and data.card
        elseif info == 15 then
          return event == fk.Deathed and target ~= player
        elseif info == 16 then
          return event == fk.FinishJudge and data.card
        elseif info == 17 then
          return event == fk.CardUseFinished and (data.card.trueName == "savage_assault" or data.card.trueName == "archery_attack")
        elseif info == 18 then
          return event == fk.Damage and target == player and data.card and data.card.trueName == "slash"
        elseif info == 19 then
          if event == fk.AfterCardsMove then
            if player.phase == Player.NotActive then
              for _, move in ipairs(data) do
                if move.from == player.id then
                  for _, inf in ipairs(move.moveInfo) do
                    if Fk:getCardById(inf.cardId).color == Card.Red and
                      (inf.fromArea == Card.PlayerHand or inf.fromArea == Card.PlayerEquip) then
                      return true
                    end
                  end
                end
              end
            end
          end
        elseif info == 20 then
          return event == fk.EventPhaseStart and target == player and player.phase == Player.Discard
        elseif info == 21 then
          return event == fk.Damaged and data.card and data.card.trueName == "slash"
        elseif info == 22 then
          return event == fk.EventPhaseStart and target == player and player.phase == Player.Draw
        elseif info == 23 then
          return event == fk.TargetConfirmed and target == player and data.card.type == Card.TypeTrick
        elseif info == 24 then
          return event == fk.ChainStateChanged and target.chained
        elseif info == 25 then
          return event == fk.Damaged and data.damageType ~= fk.NormalDamage
        elseif info == 26 then
          if event == fk.AfterCardsMove then
            for _, move in ipairs(data) do
              if move.from and room:getPlayerById(move.from):isKongcheng() then
                for _, inf in ipairs(move.moveInfo) do
                  if inf.fromArea == Card.PlayerHand then
                    return true
                  end
                end
              end
            end
          end
        elseif info == 27 then
          return event == fk.HpChanged and target == player
        elseif info == 28 then
          return event == fk.RoundStart
        elseif info == 29 then
          return event == fk.DamageCaused and target ~= nil
        elseif info == 30 then
          return event == fk.DamageInflicted
        end
      end
    end,
    on_cost = function(self, event, target, player, data)
      local room = player.room
      local info = room:getBanner("honor_tianshu_skills")[self.name][2]
      local prompt = Fk:translate(":honor_tianshu_effects"..info)
      self.cost_data = nil
      if info == 1 then
        return room:askForSkillInvoke(player, self.name, nil, prompt)
      elseif info == 2 then
        local targets = table.filter(room:getOtherPlayers(player), function (p)
          return not p:isAllNude()
        end)
        if table.find(player:getCardIds("hej"), function (id)
          return not player:prohibitDiscard(id)
        end) then
          table.insert(targets, player)
        end
        if #targets == 0 then return end
        local to = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, prompt, self.name, true)
        if #to > 0 then
          self.cost_data = {tos = to}
          return true
        end
      elseif info == 3 then
        return room:askForSkillInvoke(player, self.name, nil, prompt)
      elseif info == 4 then
        if player:isNude() then return end
        local cards = room:askForDiscard(player, 1, 999, true, self.name, true, nil, prompt, true)
        if #cards > 0 then
          self.cost_data = {cards = cards}
          return true
        end
      elseif info == 5 then
        if data.card and room:getCardArea(data.card) == Card.Processing then
          return room:askForSkillInvoke(player, self.name, nil, prompt)
        end
      elseif info == 6 then
        local use = U.askForUseVirtualCard(room, player, "slash", nil, self.name, prompt, true, true, true, true, nil, true)
        if use then
          self.cost_data = use
          return true
        end
      elseif info == 7 then
        local targets = table.filter(room:getOtherPlayers(player), function (p)
          return not p:isAllNude()
        end)
        if #player:getCardIds("ej") > 0 then
          table.insert(targets, player)
        end
        if #targets == 0 then return end
        local to = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, prompt, self.name, true)
        if #to > 0 then
          self.cost_data = {tos = to}
          return true
        end
      elseif info == 8 then
        if player:isWounded() then
          return room:askForSkillInvoke(player, self.name, nil, prompt)
        end
      elseif info == 9 then
        return room:askForSkillInvoke(player, self.name, nil, prompt)
      elseif info == 10 then
        if player:getHandcardNum() < player.maxHp then
          return room:askForSkillInvoke(player, self.name, nil, prompt)
        end
      elseif info == 11 then
        local to = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1, prompt, self.name, true)
        if #to > 0 then
          self.cost_data = {tos = to}
          return true
        end
      elseif info == 12 then
        local to = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1, prompt, self.name, true)
        if #to > 0 then
          self.cost_data = {tos = to}
          return true
        end
      elseif info == 13 then
        return room:askForSkillInvoke(player, self.name, nil, prompt)
      elseif info == 14 then
        local targets = room:getOtherPlayers(player)
        if #targets == 0 then return end
        local to = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, prompt, self.name, true)
        if #to > 0 then
          self.cost_data = {tos = to}
          return true
        end
      elseif info == 15 then
        if not player:isKongcheng() and data.card then
          local card = room:askForCard(player, 1, 1, false, self.name, true, nil, prompt)
          if #card > 0 then
            self.cost_data = {cards = card}
            return true
          end
        end
      elseif info == 16 then
        if data.card and room:getCardArea(data.card) == Card.Processing then
          return room:askForSkillInvoke(player, self.name, nil, prompt)
        end
      elseif info == 17 then
        if table.find(room.alive_players, function (p)
          return p.maxHp > player.maxHp
        end) then
          return room:askForSkillInvoke(player, self.name, nil, prompt)
        end
      elseif info == 18 then
        if player:isKongcheng() then return end
        local targets = table.filter(room:getOtherPlayers(player), function (p)
          return p:isWounded() and player:canPindian(p)
        end)
        if #targets == 0 then return end
        local to = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, prompt, self.name, true)
        if #to > 0 then
          self.cost_data = {tos = to}
          return true
        end
      elseif info == 19 then
        local to = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 2, prompt, self.name, true)
        if #to > 0 then
          room:sortPlayersByAction(to)
          self.cost_data = {tos = to}
          return true
        end
      elseif info == 20 then
        local to = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1, prompt, self.name, true)
        if #to > 0 then
          self.cost_data = {tos = to}
          return true
        end
      elseif info == 21 then
        return room:askForSkillInvoke(player, self.name, nil, prompt)
      elseif info == 22 then
        return room:askForSkillInvoke(player, self.name, nil, prompt)
      elseif info == 23 then
        return room:askForSkillInvoke(player, self.name, nil, prompt)
      elseif info == 24 then
        local to = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1, prompt, self.name, true)
        if #to > 0 then
          self.cost_data = {tos = to}
          return true
        end
      elseif info == 25 then
        if #player:getCardIds("he") < 2 then return end
        local targets = table.filter(room:getOtherPlayers(player), function (p)
          return p:isWounded()
        end)
        if #targets == 0 then return end
        local ids = table.filter(player:getCardIds("he"), function (id)
          return not player:prohibitDiscard(id)
        end)
        local to, cards = room:askForChooseCardsAndPlayers(player, 2, 2, table.map(targets, Util.IdMapper), 1, 1,
          tostring(Exppattern{ id = ids }), prompt, self.name, true)
        if #to > 0 and #cards > 0 then
          self.cost_data = {tos = to, cards = cards}
          return true
        end
      elseif info == 26 then
        return room:askForSkillInvoke(player, self.name, nil, prompt)
      elseif info == 27 then
        return room:askForSkillInvoke(player, self.name, nil, prompt)
      elseif info == 28 then
        local success, dat = room:askForUseActiveSkill(player, "honor_tianshu_active", prompt, true, {tianshu28 = "e"}, false)
        if success and dat then
          room:sortPlayersByAction(dat.targets)
          self.cost_data = {tos = dat.targets}
          return true
        end
      elseif info == 29 then
        local success, dat = room:askForUseActiveSkill(player, "honor_tianshu_active", prompt, true, {tianshu28 = "h"}, false)
        if success and dat then
          room:sortPlayersByAction(dat.targets)
          self.cost_data = {tos = dat.targets}
          return true
        end
      elseif info == 30 then
        return room:askForSkillInvoke(player, self.name, nil, prompt)
      end
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      local info = room:getBanner("honor_tianshu_skills")[self.name][2]
      local source = room:getBanner("honor_tianshu_skills")[self.name][3]
      if source == player.id and player:usedSkillTimes(self.name, Player.HistoryGame) > 2 then
        player:setSkillUseHistory(self.name, 0, Player.HistoryGame)
        room:handleAddLoseSkills(player, "-"..self.name, nil, true, false)
        local banner = room:getBanner("honor_tianshu_skills")
        banner[self.name] = nil
        room:setBanner("honor_tianshu_skills", banner)
      else
        local mark = player:getTableMark("@[honor_tianshu]")
        for i = 1, #mark do
          if mark[i].skillName == self.name then
            mark[i].skillTimes = 3 - player:usedSkillTimes(self.name, Player.HistoryGame)
            mark[i].visible = true
            break
          end
        end
        room:setPlayerMark(player, "@[honor_tianshu]", mark)
      end
      switch(info, {
        [1] = function ()
          player:drawCards(1, self.name)
        end,
        [2] = function ()
          local to = room:getPlayerById(self.cost_data.tos[1])
          if to == player then
            local cards = table.filter(player:getCardIds("hej"), function (id)
              return not player:prohibitDiscard(id)
            end)
            local card = room:askForCard(player, 1, 1, true, self.name, false, tostring(Exppattern{ id = cards }),
              "#honor_tianshu2-discard::"..player.id, player:getCardIds("j"))
            room:throwCard(card, self.name, player, player)
          else
            local card = room:askForCardChosen(player, to, "hej", self.name, "#honor_tianshu2-discard::"..to.id)
            room:throwCard(card, self.name, to, player)
          end
        end,
        [3] = function ()
          room:askForGuanxing(player, room:getNCards(3))
        end,
        [4] = function ()
          room:throwCard(self.cost_data.cards, self.name, player, player)
          if player.dead then return end
          player:drawCards(#self.cost_data.cards, self.name)
        end,
        [5] = function ()
          room:moveCardTo(data.card, Card.PlayerHand, player, fk.ReasonJustMove, self.name, nil, true, player.id)
        end,
        [6] = function ()
          room:useCard(self.cost_data)
        end,
        [7] = function ()
          local to = room:getPlayerById(self.cost_data.tos[1])
          local flag = to == player and "ej" or "hej"
          local card = room:askForCardChosen(player, to, flag, self.name, "#honor_tianshu7-prey::"..to.id)
          room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, false, player.id)
        end,
        [8] = function ()
          room:recover{
            who = player,
            num = 1,
            recoverBy = player,
            skillName = self.name
          }
        end,
        [9] = function ()
          player:drawCards(3, self.name)
          if not player.dead then
            room:askForDiscard(player, 1, 1, true, self.name, false)
          end
        end,
        [10] = function ()
          player:drawCards(math.min(player.maxHp - player:getHandcardNum(), 5), self.name)
        end,
        [11] = function ()
          local to = room:getPlayerById(self.cost_data.tos[1])
          room:addPlayerMark(to, "@@honor_tianshu11", 1)
          room:addPlayerMark(to, MarkEnum.UncompulsoryInvalidity, 1)
        end,
        [12] = function ()
          local to = room:getPlayerById(self.cost_data.tos[1])
          to:drawCards(2, self.name)
          if not to.dead then
            to:turnOver()
          end
        end,
        [13] = function ()
          table.insertIfNeed(data.nullifiedTargets, player.id)
        end,
        [14] = function ()
          local to = room:getPlayerById(self.cost_data.tos[1])
          local judge = {
            who = to,
            reason = self.name,
            pattern = ".|.|spade",
          }
          room:judge(judge)
          if judge.card.suit == Card.Spade and not to.dead then
            room:damage{
              from = player,
              to = to,
              damage = 2,
              damageType = fk.ThunderDamage,
              skillName = self.name,
            }
          end
        end,
        [15] = function ()
          local card = Fk:getCardById(self.cost_data.cards[1])
          room:retrial(card, player, data, self.name, true)
        end,
        [16] = function ()
          room:moveCardTo(data.card, Card.PlayerHand, player, fk.ReasonJustMove, self.name, nil, true, player.id)
        end,
        [17] = function ()
          room:changeMaxHp(player, 1)
        end,
        [18] = function ()
          local to = room:getPlayerById(self.cost_data.tos[1])
          local pindian = player:pindian({to}, self.name)
          if pindian.results[to.id].winner == player then
            if not player.dead and not to.dead and not to:isNude() then
              local cards = room:askForCardsChosen(player, to, math.min(#to:getCardIds("he"), 2), 2, "he", self.name,
                "#honor_tianshu18-prey::"..to.id)
              room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, false, player.id)
            end
          end
        end,
        [19] = function ()
          for _, id in ipairs(self.cost_data.tos) do
            local p = room:getPlayerById(id)
            if not p.dead then
              p:drawCards(1, self.name)
            end
          end
        end,
        [20] = function ()
          local to = room:getPlayerById(self.cost_data.tos[1])
          room:addPlayerMark(to, MarkEnum.AddMaxCards, 2)
          room:addPlayerMark(to, "honor_tianshu20", 2)
        end,
        [21] = function ()
          local cards = room:getCardsFromPileByRule(".|.|.|.|.|^basic", 2)
          if #cards > 0 then
            room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonJustMove, self.name, nil, false, player.id)
          end
        end,
        [22] = function ()
          local cards = room:getCardsFromPileByRule(".|.|.|.|.|trick", 2)
          if #cards > 0 then
            room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonJustMove, self.name, nil, false, player.id)
          end
        end,
        [23] = function ()
          player:drawCards(4, self.name)
          if not player.dead then
            player:turnOver()
          end
        end,
        [24] = function ()
          local to = room:getPlayerById(self.cost_data.tos[1])
          room:addTableMark(player, "honor_tianshu24", to.id)
        end,
        [25] = function ()
          room:throwCard(self.cost_data.cards, self.name, player, player)
          local to = room:getPlayerById(self.cost_data.tos[1])
          if not player.dead and player:isWounded() then
            room:recover{
              who = player,
              num = 1,
              recoverBy = player,
              skillName = self.name
            }
          end
          if not to.dead and to:isWounded() then
            room:recover{
              who = to,
              num = 1,
              recoverBy = player,
              skillName = self.name
            }
          end
        end,
        [26] = function ()
          data.damage = data.damage + 1
        end,
        [27] = function ()
          room:loseHp(player, 1, self.name)
          if not player.dead then
            player:drawCards(3, self.name)
          end
        end,
        [28] = function ()
          local targets = table.map(self.cost_data.tos, Util.Id2PlayerMapper)
          U.swapCards(room, player, targets[1], targets[2], targets[1]:getCardIds("e"), targets[2]:getCardIds("e"), self.name,
            Card.PlayerEquip)
        end,
        [29] = function ()
          local targets = table.map(self.cost_data.tos, Util.Id2PlayerMapper)
          U.swapHandCards(room, player, targets[1], targets[2], self.name)
        end,
        [30] = function ()
          if data.from and not data.from.dead then
            data.from:drawCards(3, self.name)
          end
          return true
        end,
      })
    end,

    --几个持续一段时间的标记效果，在青书中清理。

    on_acquire = function (self, player, is_start)
      local room = player.room
      local info = room:getBanner("honor_tianshu_skills")[self.name]
      local mark = player:getTableMark("@[honor_tianshu]")
      table.insert(mark, {
        skillName = self.name,
        skillTimes = info[3] == player.id and 3 or 1,
        skillInfo = Fk:translate(":honor_tianshu_triggers"..info[1]).."，"..Fk:translate(":honor_tianshu_effects"..info[2]).."。",
        owner = { player.id, info[3] },
        visible = false
      })
      room:setPlayerMark(player, "@[honor_tianshu]", mark)
    end,

    on_lose = function (self, player, is_death)
      local room = player.room
      local mark = player:getTableMark("@[honor_tianshu]")
      for i = #mark, 1, -1 do
        if mark[i].skillName == self.name then
          table.remove(mark, i)
        end
      end
      room:setPlayerMark(player, "@[honor_tianshu]", #mark > 0 and mark or 0)
      player:setSkillUseHistory(self.name, 0, Player.HistoryGame)
    end,
  }
  Fk:addSkill(tianshu)
  Fk:loadTranslationTable{
    ["honor_tianshu"..loop] = "天书",
    [":honor_tianshu"..loop] = "未翻开的天书。",
    ["honor_tianshu_triggers"..loop] = "时机",
    ["honor_tianshu_effects"..loop] = "效果",
  }
end
local tianshu_active = fk.CreateActiveSkill{
  name = "honor_tianshu_active",
  card_num = 0,
  target_num = 2,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards, _, extra_data)
    if #selected < 2 then
      if #selected == 0 then
        return true
      elseif #selected == 1 then
        local area = extra_data.tianshu28
        return #Fk:currentRoom():getPlayerById(selected[1]):getCardIds(area) > 0 or
          #Fk:currentRoom():getPlayerById(to_select):getCardIds(area) > 0
      end
    end
  end,
}
Fk:addQmlMark{
  name = "honor_tianshu",
  how_to_show = function(name, value)
    if type(value) == "table" then
      return tostring(#value)
    end
    return " "
  end,
  qml_path = "packages/wild_collection/qml/Tianshu"
}
Fk:addSkill(tianshu_active)
nanhualaoxian:addSkill(qingshu)
nanhualaoxian:addSkill(ol__shoushu)
nanhualaoxian:addSkill(hedao)
Fk:loadTranslationTable{
  ["honor_ol__nanhualaoxian"] = "南华老仙",
  ["#honor_ol__nanhualaoxian"] = "逍遥仙游",
  ["designer:honor_ol__nanhualaoxian"] = "某个神人",

  ["honor_qingshu"] = "青书",
  [":honor_qingshu"] = "锁定技，游戏开始时，你的准备阶段和结束阶段，你书写一册<a href='tianshu_href'>“天书”</a>。",
  ["honor_ol__shoushu"] = "授术",
  [":honor_ol__shoushu"] = "出牌阶段限一次，你可以将一册未翻开的<a href='tianshu_href'>“天书”</a>交给一名其他角色。",
  ["honor_hedao"] = "合道",
  [":honor_hedao"] = "锁定技，游戏开始时，你可以至多拥有两册<a href='tianshu_href'>“天书”</a>。你的首次濒死结算后，你可以至多拥有三册"..
  "<a href='honor_tianshu_href'>“天书”</a>。",
  ["honor_tianshu_href"] = "从随机三个时机和三个效果中各选择一个组合为一个“天书”技能。<br>"..
  "“天书”技能初始可使用三次，若交给其他角色则可使用次数改为一次，当次数用完后销毁。<br>"..
  "当一名角色将获得“天书”时，若数量将超过其可拥有“天书”的上限，则选择一个已有“天书”替换。",
  ["#honor_qingshu-choice_trigger"] = "请为天书选择一个时机",
  ["#honor_qingshu-choice_effect"] = "请为此时机选择一个效果：<br>%arg，",
  ["#honor_ol__shoushu-discard"] = "你的“天书”超出上限，请删除一个",
  ["#honor_ol__shoushu"] = "授术：你可以将一册未翻开的“天书”交给一名其他角色",
  ["#honor_ol__shoushu-give"] = "授术：选择交给 %dest 的“天书”",

  ["@[honor_tianshu]"] = "天书",
  ["#honor_tianshu2-discard"] = "弃置 %dest 区域内一张牌",
  ["#honor_tianshu7-prey"] = "获得 %dest 区域内一张牌",
  ["#honor_tianshu18-prey"] = "获得 %dest 两张牌",
  ["@@honor_tianshu11"] = "非锁定技失效",
  ["honor_tianshu_active"] = "天书",

  [":honor_tianshu_triggers1"] = "你使用牌后",
  [":honor_tianshu_triggers2"] = "其他角色对你使用牌后",
  [":honor_tianshu_triggers3"] = "出牌阶段开始时",
  [":honor_tianshu_triggers4"] = "你受到伤害后",
  [":honor_tianshu_triggers5"] = "准备阶段",
  [":honor_tianshu_triggers6"] = "结束阶段",
  [":honor_tianshu_triggers7"] = "你造成伤害后",
  [":honor_tianshu_triggers8"] = "你成为【杀】的目标时",
  [":honor_tianshu_triggers9"] = "一名角色进入濒死时",
  [":honor_tianshu_triggers10"] = "你失去装备牌后",
  [":honor_tianshu_triggers11"] = "你使用或打出【闪】时",
  [":honor_tianshu_triggers12"] = "当一张判定牌生效前",
  [":honor_tianshu_triggers13"] = "你失去手牌后",
  [":honor_tianshu_triggers14"] = "你使用的牌被抵消后",
  [":honor_tianshu_triggers15"] = "一名其他角色死亡后",
  [":honor_tianshu_triggers16"] = "当一张判定牌生效后",
  [":honor_tianshu_triggers17"] = "【南蛮入侵】或【万箭齐发】结算后",
  [":honor_tianshu_triggers18"] = "你使用【杀】造成伤害后",
  [":honor_tianshu_triggers19"] = "你于回合外失去红色牌后",
  [":honor_tianshu_triggers20"] = "弃牌阶段开始时",
  [":honor_tianshu_triggers21"] = "一名角色受到【杀】的伤害后",
  [":honor_tianshu_triggers22"] = "摸牌阶段开始时",
  [":honor_tianshu_triggers23"] = "你成为普通锦囊牌的目标后",
  [":honor_tianshu_triggers24"] = "一名角色进入连环状态后",
  [":honor_tianshu_triggers25"] = "一名角色受到属性伤害后",
  [":honor_tianshu_triggers26"] = "一名角色失去最后的手牌后",
  [":honor_tianshu_triggers27"] = "你的体力值变化后",
  [":honor_tianshu_triggers28"] = "每轮开始时",
  [":honor_tianshu_triggers29"] = "一名角色造成伤害时",
  [":honor_tianshu_triggers30"] = "一名角色受到伤害时",

  [":honor_tianshu_effects1"] = "你可以摸一张牌",
  [":honor_tianshu_effects2"] = "你可以弃置一名角色区域内的一张牌",
  [":honor_tianshu_effects3"] = "你可以观看牌堆顶的3张牌，以任意顺序置于牌堆顶或牌堆底",
  [":honor_tianshu_effects4"] = "你可以弃置任意张牌，摸等量张牌",
  [":honor_tianshu_effects5"] = "你可以获得造成伤害的牌",
  [":honor_tianshu_effects6"] = "你可以视为使用一张无距离次数限制的【杀】",
  [":honor_tianshu_effects7"] = "你可以获得一名角色区域内的一张牌",
  [":honor_tianshu_effects8"] = "你可以回复1点体力",
  [":honor_tianshu_effects9"] = "你可以摸3张牌，弃置1张牌",
  [":honor_tianshu_effects10"] = "你可以摸牌至体力上限（至多摸5张）",
  [":honor_tianshu_effects11"] = "你可以令一名角色非锁定技失效直到其下回合开始",
  [":honor_tianshu_effects12"] = "你可以令一名角色摸2张牌并翻面",
  [":honor_tianshu_effects13"] = "你可以令此牌对你无效",
  [":honor_tianshu_effects14"] = "你可以令一名其他角色判定，若结果为♠，你对其造成2点雷电伤害",
  [":honor_tianshu_effects15"] = "你可以用一张手牌替换判定牌",
  [":honor_tianshu_effects16"] = "你可以获得此判定牌",
  [":honor_tianshu_effects17"] = "若你不是体力上限最高的角色，你可以增加1点体力上限",
  [":honor_tianshu_effects18"] = "你可以与一名已受伤角色拼点，若你赢，你获得其两张牌",
  [":honor_tianshu_effects19"] = "你可以令至多两名角色各摸一张牌",
  [":honor_tianshu_effects20"] = "你可以令一名角色的手牌上限+2直到其回合结束",
  [":honor_tianshu_effects21"] = "你可以获得两张非基本牌",
  [":honor_tianshu_effects22"] = "你可以获得两张锦囊牌",
  [":honor_tianshu_effects23"] = "你可以摸4张牌并翻面",
  [":honor_tianshu_effects24"] = "你可以令你对一名角色使用牌无距离次数限制直到你的回合结束",
  [":honor_tianshu_effects25"] = "你可以弃置两张牌，令你和一名其他角色各回复1点体力",
  [":honor_tianshu_effects26"] = "你可以令此伤害值+1",
  [":honor_tianshu_effects27"] = "你可以失去1点体力，摸3张牌",
  [":honor_tianshu_effects28"] = "你可以交换两名角色装备区的牌",
  [":honor_tianshu_effects29"] = "你可以交换两名角色手牌区的牌",
  [":honor_tianshu_effects30"] = "你可以防止此伤害，令伤害来源摸3张牌",

  ["$honor_qingshu1"] = "赤紫青黄，唯记万变其一。",
  ["$honor_qingshu2"] = "天地万法，皆在此书之中。",
  ["$honor_qingshu3"] = "以小篆记大道，则道可道。",
  ["$honor_ol__shoushu1"] = "此书载天地至理，望汝珍视如命。",
  ["$honor_ol__shoushu2"] = "天书非凡物，字字皆玄机。",
  ["$honor_ol__shoushu3"] = "我得道成仙，当出世化生人中。",
  ["$honor_hedao1"] = "不参黄泉，难悟大道。",
  ["$honor_hedao2"] = "道者，亦置之死地而后生。",
  ["$honor_hedao3"] = "因果开茅塞，轮回似醍醐。",
  ["~honor_ol__nanhualaoxian"] = "尔生异心，必获恶报！",
}

local simazhao = General(extension, "honor_js__simazhao", "wei", 4)
simazhao.total_hidden= true
local qiantun = fk.CreateActiveSkill{
  name = "honor_qiantun",
  anim_type = "control",
  card_num = 0,
  target_num = 1,
  prompt = "#honor_qiantun",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= Self.id and not Fk:currentRoom():getPlayerById(to_select):isKongcheng()
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local cards = room:askForCard(target, 1, 999, false, self.name, false, nil, "#honor_qiantun-ask:"..player.id)
    target:showCards(cards)
    cards = table.filter(cards, function (id)
      return table.contains(target:getCardIds("h"), id)
    end)
    if player.dead or target.dead or #cards == 0 or not player:canPindian(target) then return end
    local pindian = {
      from = player,
      tos = {target},
      reason = self.name,
      fromCard = nil,
      results = {},
      extra_data = {
        qiantun = {
          to = target.id,
          cards = cards,
        },
      },
    }
    room:pindian(pindian)
    if player.dead or target.dead then return end
    if pindian.results[target.id].winner == player then
      cards = table.filter(target:getCardIds("h"), function (id)
        return table.contains(cards, id)
      end)
    else
      cards = table.filter(target:getCardIds("h"), function (id)
        return not table.contains(cards, id)
      end)
    end
    if #cards > 0 then
      room:obtainCard(player, cards, false, fk.ReasonPrey, player.id, self.name)
    end
    if not player.dead and not player:isKongcheng() then
      player:showCards(player:getCardIds("h"))
    end
  end,
}
local qiantun_trigger = fk.CreateTriggerSkill{
  name = "#honor_qiantun_trigger",
  mute = true,
  events = {fk.StartPindian},
  can_trigger = function(self, event, target, player, data)
    if player == data.from and data.reason == "honor_qiantun" and data.extra_data and data.extra_data.qiantun then
      for _, to in ipairs(data.tos) do
        if not (data.results[to.id] and data.results[to.id].toCard) and
          data.extra_data.qiantun.to == to.id and
          table.find(data.extra_data.qiantun.cards, function (id)
            return table.contains(to:getCardIds("h"), id)
          end) then
          return true
        end
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, to in ipairs(data.tos) do
      if not (to.dead or to:isKongcheng() or (data.results[to.id] and data.results[to.id].toCard)) and
        data.extra_data.qiantun.to == to.id then
        local cards = table.filter(data.extra_data.qiantun.cards, function (id)
          return table.contains(to:getCardIds("h"), id)
        end)
        if #cards > 0 then
          local card = room:askForCard(to, 1, 1, false, "honor_qiantun", false, tostring(Exppattern{ id = cards }),
            "#honor_qiantun-pindian:"..data.from.id)
          data.results[to.id] = data.results[to.id] or {}
          data.results[to.id].toCard = Fk:getCardById(card[1])
        end
      end
    end
  end,
}
local xiezheng = fk.CreateTriggerSkill{
  name = "honor_xiezheng",
  anim_type = "control",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Finish and
      table.find(player.room.alive_players, function (p)
        return not p:isKongcheng()
      end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function (p)
      return not p:isKongcheng()
    end)
    local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 3,
      "#honor_xiezheng-choose", self.name, true)
    if #tos > 0 then
      room:sortPlayersByAction(tos)
      self.cost_data = {tos = tos}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, id in ipairs(self.cost_data.tos) do
      local p = room:getPlayerById(id)
      if not p.dead and not p:isKongcheng() then
        local card = room:askForCard(p, 1, 1, false, self.name, false, nil, "#honor_xiezheng-ask:"..player.id)
        room:moveCards({
          ids = card,
          from = id,
          toArea = Card.DrawPile,
          moveReason = fk.ReasonPut,
          skillName = self.name,
        })
      end
    end
    if player.dead then return end
    local use = U.askForUseVirtualCard(room, player, "enemy_at_the_gates", nil, self.name, "#honor_xiezheng-use", false)
    if use and not player.dead and not (use.extra_data and use.extra_data.xiezheng_damageDealt) then
      room:loseHp(player, 1, self.name)
    end
  end,

  refresh_events = {fk.Damage},
  can_refresh = function (self, event, target, player, data)
    return target == player and data.card and data.card.trueName == "slash" and
      table.contains(data.card.skillNames, "enemy_at_the_gates_skill")
  end,
  on_refresh = function (self, event, target, player, data)
    local e = player.room.logic:getCurrentEvent().parent
    while e do
      if e.event == GameEvent.UseCard then
        local use = e.data[1]
        if use.card.name == "enemy_at_the_gates" and table.contains(use.card.skillNames, "honor_honor_xiezheng") then
          use.extra_data = use.extra_data or {}
          use.extra_data.xiezheng_damageDealt = true
          return
        end
      end
      e = e.parent
    end
  end,
}
local zhaoxiong = fk.CreateTriggerSkill{
  name = "honor_zhaoxiong",
  anim_type = "special",
  events = {fk.EventPhaseStart},
  frequency = Skill.Limited,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Start and
      player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and
      player:isWounded() and player:usedSkillTimes("honor_xiezheng", Player.HistoryGame) > 0
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#honor_zhaoxiong-invoke")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player.general == "honor_js__simazhao" then
      player.general = "honor_js2__simazhao"
      room:broadcastProperty(player, "general")
    elseif player.deputyGeneral == "honor_js__simazhao" then
      player.deputyGeneral = "honor_js2__simazhao"
      room:broadcastProperty(player, "deputyGeneral")
    end
    if player.kingdom ~= "jin" then
      room:changeKingdom(player, "jin", true)
    end
    if not player.dead then
      room:handleAddLoseSkills(player, "-honor_qiantun|honor_weisi|honor_dangyi", nil, true, false)
    end
  end,
}
qiantun:addRelatedSkill(qiantun_trigger)
simazhao:addSkill(qiantun)
simazhao:addSkill(xiezheng)
simazhao:addSkill(zhaoxiong)
Fk:loadTranslationTable{
  ["honor_js__simazhao"] = "司马昭",
  ["#honor_js__simazhao"] = "堕节肇业",
  ["illustrator:honor_js__simazhao"] = "云涯",

  ["honor_qiantun"] = "谦吞",
  [":honor_qiantun"] = "出牌阶段限一次，你可以令一名其他角色展示至少一张手牌，并与其拼点，其本次拼点牌只能从展示牌中选择。若你赢，你获得其展示的手牌；"..
  "若你没赢，你获得其未展示的手牌。然后你展示手牌。",
  ["honor_xiezheng"] = "挟征",
  [":honor_xiezheng"] = "结束阶段，你可以令至多三名角色依次将一张手牌置于牌堆顶，然后视为你使用一张【兵临城下】，结算后若未造成过伤害，你失去1点体力。",
  ["honor_zhaoxiong"] = "昭凶",
  [":honor_zhaoxiong"] = "限定技，准备阶段，若你已受伤且发动过〖挟征〗，你可以变更势力至晋，失去〖谦吞〗，获得〖威肆〗〖荡异〗。",
  ["#honor_qiantun"] = "谦吞：令一名角色展示任意张手牌并与其拼点，若赢，你获得展示牌；若没赢，你获得其未展示的手牌",
  ["#honor_qiantun-ask"] = "谦吞：请展示任意张手牌，你将只能用这些牌与 %src 拼点，根据拼点结果其获得你的展示牌或未展示牌！",
  ["#honor_qiantun-pindian"] = "谦吞：你只能用这些牌与 %src 拼点！若其赢，其获得你的展示牌；若其没赢，其获得你未展示的手牌",
  ["#honor_xiezheng-choose"] = "挟征：令至多三名角色依次将一张手牌置于牌堆顶，然后你视为使用一张【兵临城下】！",
  ["#honor_xiezheng-ask"] = "挟征：%src 将视为使用【兵临城下】！请将一张手牌置于牌堆顶",
  ["#honor_xiezheng-use"] = "挟征：视为使用一张【兵临城下】！若未造成伤害，你失去1点体力",
  ["#honor_zhaoxiong-invoke"] = "昭凶：是否变为晋势力、失去“谦吞”、获得“威肆”和“荡异”？",
}

local simazhao2 = General(extension, "honor_js2__simazhao", "jin", 4)
simazhao2.total_hidden = true
local weisi = fk.CreateActiveSkill{
  name = "honor_weisi",
  anim_type = "offensive",
  card_num = 0,
  target_num = 1,
  prompt = "#honor_weisi",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= Self.id
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local cards = room:askForCard(target, 1, 999, false, self.name, true, nil, "#honor_weisi-ask:"..player.id)
    if #cards > 0 then
      target:addToPile("$honor_weisi", cards, false, self.name, target.id)
    end
    if player.dead or target.dead then return end
    room:useVirtualCard("duel", nil, player, target, self.name)
  end,
}
local weisi_delay = fk.CreateTriggerSkill{
  name = "#honor_weisi_delay",
  mute = true,
  events = {fk.Damage, fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if event == fk.Damage then
      return target == player and not player.dead and player.room.logic:damageByCardEffect(true) and
        data.card and table.contains(data.card.skillNames, "honor_weisi") and
        not data.to:isKongcheng()
    elseif event == fk.TurnEnd then
      return #player:getPile("$honor_weisi") > 0
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.Damage then
      room:moveCardTo(data.to:getCardIds("h"), Card.PlayerHand, player, fk.ReasonPrey, "honor_weisi", nil, false, player.id)
    elseif event == fk.TurnEnd then
      room:moveCardTo(player:getPile("$honor_weisi"), Card.PlayerHand, player, fk.ReasonJustMove, "honor_weisi", nil, false, player.id)
    end
  end,
}
local dangyi = fk.CreateTriggerSkill{
  name = "honor_dangyi",
  anim_type = "offensive",
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) < 3
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#honor_dangyi-invoke::"..data.to.id..":"..player:getMark("@honor_dangyi"))
  end,
  on_use = function(self, event, target, player, data)
    player.room:removePlayerMark(player, "@honor_dangyi", 1)
    data.damage = data.damage + 1
  end,

  refresh_events = {fk.EventAcquireSkill, fk.EventLoseSkill},
  can_refresh = function (self, event, target, player, data)
    return target == player and data == self
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "@honor_dangyi", 3 - player:usedSkillTimes(self.name, Player.HistoryGame))
  end,
}
dangyi.permanent_skill = true
weisi:addRelatedSkill(weisi_delay)
simazhao2:addSkill(weisi)
simazhao2:addSkill("honor_xiezheng")
simazhao2:addSkill(dangyi)
simazhao:addRelatedSkill("honor_weisi")
simazhao:addRelatedSkill("honor_dangyi")
Fk:loadTranslationTable{
  ["honor_js2__simazhao"] = "司马昭",
  ["#honor_js2__simazhao"] = "独祆吞天",
  ["illustrator:honor_js2__simazhao"] = "腥鱼仔",

  ["honor_weisi"] = "威肆",
  [":honor_weisi"] = "出牌阶段限一次，你可以选择一名其他角色，令其将任意张手牌移出游戏直到回合结束，然后视为对其使用一张【决斗】，"..
  "此牌对其造成伤害后，你获得其所有手牌。",
  ["honor_dangyi"] = "荡异",
  [":honor_dangyi"] = "持恒技，每局游戏限三次，当你造成伤害时，你可以令此伤害值+1。",
  ["#honor_weisi"] = "威肆：令一名角色将任意张手牌移出游戏直到回合结束，然后视为对其使用【决斗】！",
  ["#honor_weisi-ask"] = "威肆：%src 将对你使用【决斗】！请将任意张手牌本回合移出游戏，【决斗】对你造成伤害后其获得你所有手牌！",
  ["$honor_weisi"] = "威肆",
  ["#honor_weisi_delay"] = "威肆",
  ["#honor_dangyi-invoke"] = "荡异：是否令你对 %dest 造成的伤害+1？（还剩%arg次！）",
  ["@honor_dangyi"] = "荡异",
}

local ol__zhugejin = General(extension, "honor_ol__zhugejin", "wu", 3)
local ol__huanshi = fk.CreateTriggerSkill{
  name = "honor_ol__huanshi",
  anim_type = "support",
  events = {fk.AskForRetrial},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and not player:isKongcheng()
  end,
  on_cost = function(self, event, target, player, data)
    if player.room:askForSkillInvoke(player,self.name, nil, "#honor_ol__huanshi-invoke::"..target.id) then
      player.room:doIndicate(player.id, {target.id})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local handcards = player:getCardIds(Player.Hand)
    local equips = player:getCardIds(Player.Equip)
    local card_data = {}
    if #handcards > 0 then
      table.insert(card_data, { "$Hand", handcards })
    end
    if #equips > 0 then
      table.insert(card_data, { "$Equip", equips })
    end
    local id = room:askForCardChosen(target, player, { card_data = card_data }, self.name)
    local card = Fk:getCardById(id)
    if not player:prohibitResponse(card) then
      room:retrial(card, player, data, self.name)
      if not player.dead and not player:isNude() then
        local cids = room:askForDiscard(player, 1, 999, true, self.name, true, ".", "#honor_ol__huanshi-discard")
        if #cids > 0 and not player.dead then
          player:drawCards(#cids, self.name)
        end
      end
    end
  end,
}
local ol__hongyuan = fk.CreateTriggerSkill{
  name = "honor_ol__hongyuan",
  anim_type = "defensive",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryPhase) < 1 and not player:isNude() then
      local currentplayer = player.room.current
      if currentplayer and currentplayer.phase <= Player.Finish and currentplayer.phase >= Player.Start then
        local x = 0
        for _, move in ipairs(data) do
          if move.to == player.id and move.toArea == Card.PlayerHand then
            x = x + #move.moveInfo
          end
        end
        return x > 1
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = table.map(room:getOtherPlayers(player, false), Util.IdMapper)
    for _ = 1, 2, 1 do
      if player.dead or player:isNude() then break end
      local tos, cardId = room:askForChooseCardAndPlayers(
        player,
        targets,
        1,
        1,
        ".",
        "#honor_ol__hongyuan-give",
        self.name,
        true,
        true
      )
      if #tos > 0 then
        room:obtainCard(tos[1], cardId, false, fk.ReasonGive)
        targets = table.filter(targets, function (pid)
          return tos[1] ~= pid and not room:getPlayerById(pid).dead
        end)
        if #targets < 1 then break end
      else
        break
      end
    end
  end,
}
local ol__mingzhe = fk.CreateTriggerSkill{
  name = "honor_ol__mingzhe",
  frequency = Skill.Compulsory,
  anim_type = "defensive",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player.phase ~= Player.Play then
      for _, move in ipairs(data) do
        if move.from == player.id and (move.to ~= player.id or (move.toArea ~= Card.PlayerHand and move.toArea ~= Card.PlayerEquip)) then
          for _, info in ipairs(move.moveInfo) do
            if (info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip) and
            Fk:getCardById(info.cardId, true).color == Card.Red then
              return true
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = {}
    for _, move in ipairs(data) do
      if move.from == player.id and (move.to ~= player.id or (move.toArea ~= Card.PlayerHand and move.toArea ~= Card.PlayerEquip)) then
        for _, info in ipairs(move.moveInfo) do
          if (info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip) and
          Fk:getCardById(info.cardId, true).color == Card.Red and room:getCardArea(info.cardId) == Card.PlayerHand then
            table.insert(cards, info.cardId)
          end
        end
      end
    end
    if #cards > 0 then
      for _, p in ipairs(player.room.alive_players) do
        local to_show = table.filter(cards, function(id)
          return room:getCardOwner(id) == p
        end)
        if #to_show > 0 then
          p:showCards(to_show)
        end
      end
    end
    player:drawCards(1, self.name)
  end,
}
ol__zhugejin:addSkill(ol__huanshi)
ol__zhugejin:addSkill(ol__hongyuan)
ol__zhugejin:addSkill(ol__mingzhe)
Fk:loadTranslationTable{
  ["honor_ol__zhugejin"] = "诸葛瑾",
  ["#honor_ol__zhugejin"] = "联盟的维系者",
  ["designer:honor_ol__zhugejin"] = "玄蝶既白",
  ["illustrator:honor_ol__zhugejin"] = "G.G.G.",

  ["honor_ol__huanshi"] = "缓释",
  [":honor_ol__huanshi"] = "当一名角色的判定结果确定前，你可以令其观看你的牌并用其中一张牌代替判定牌，然后你可以重铸任意张牌。",
  ["honor_ol__hongyuan"] = "弘援",
  [":honor_ol__hongyuan"] = "每阶段限一次，当你得到牌后，若这些牌数大于1，你可以依次将至多两张牌交给等量的角色。",
  ["honor_ol__mingzhe"] = "明哲",
  [":honor_ol__mingzhe"] = "锁定技，当你于出牌阶段外失去红色牌后，你令手牌区里有这些牌的角色各展示之且你摸一张牌。",

  ["#honor_ol__huanshi-invoke"] = "缓释：你可以令 %dest 观看你的牌并打出其中一张牌修改其判定",
  ["#honor_ol__huanshi-discard"] = "缓释：你可以弃置任意张牌并摸等量牌。",
  ["#honor_ol__hongyuan-give"] = "弘援：你可以选择一张牌交给一名角色",

  ["$honor_ol__huanshi1"] = "不因困顿夷初志，肯为联蜀改阵营。",
  ["$honor_ol__huanshi2"] = "合纵连横，只为天下苍生。",
  ["$honor_ol__hongyuan1"] = "吾已料有所困，援兵不久必至。",
  ["$honor_ol__hongyuan2"] = "恪守信义，方为上策。",
  ["$honor_ol__mingzhe1"] = "乱世，当稳中求胜。",
  ["$honor_ol__mingzhe2"] = "明哲维天，临君下土。",
  ["~honor_ol__zhugejin"] = "联盟若能得以维系，吾……无他愿矣……",
}

local chengpu = General(extension, "honor_ol_ex__chengpu", "wu", 4)
local ol_ex__lihuo = fk.CreateTriggerSkill{
  name = "honor_ol_ex__lihuo",
  anim_type = "offensive",
  events = {fk.AfterCardUseDeclared, fk.AfterCardTargetDeclared},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == fk.AfterCardUseDeclared then
        return data.card.trueName == "slash" and data.card.name ~= "fire__slash"
      elseif event == fk.AfterCardTargetDeclared then
        return data.card.name == "fire__slash" and #player.room:getUseExtraTargets(data) > 0
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardUseDeclared then
      return room:askForSkillInvoke(player, self.name, nil, "#honor_ol_ex__lihuo-invoke:::"..data.card:toLogString())
    elseif event == fk.AfterCardTargetDeclared then
      local tos = room:askForChoosePlayers(player, room:getUseExtraTargets(data), 1, 1,
        "#lihuo-choose:::"..data.card:toLogString(), self.name, true)
      if #tos > 0 then
        self.cost_data = tos
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.AfterCardUseDeclared then
      local card = Fk:cloneCard("fire__slash", data.card.suit, data.card.number)
      for k, v in pairs(data.card) do
        if card[k] == nil then
          card[k] = v
        end
      end
      if data.card:isVirtual() then
        card.subcards = data.card.subcards
      else
        card.id = data.card.id
      end
      card.skillNames = data.card.skillNames
      data.card = card
      data.extra_data = data.extra_data or {}
      data.extra_data.ol_ex__lihuo = data.extra_data.ol_ex__lihuo or {}
      table.insert(data.extra_data.ol_ex__lihuo, player.id)
    elseif event == fk.AfterCardTargetDeclared then
      table.insert(data.tos, self.cost_data)
    end
  end,
}
local ol_ex__lihuo_delay = fk.CreateTriggerSkill{
  name = "#honor_ol_ex__lihuo_delay",
  events = {fk.CardUseFinished},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return not player.dead and data.damageDealt and data.extra_data and data.extra_data.ol_ex__lihuo and
    table.contains(data.extra_data.ol_ex__lihuo, player.id)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if #room:askForDiscard(player, 1, 1, true, "honor_ol_ex__lihuo", true, ".", "#honor_ol_ex__lihuo-discard") == 0 then
      room:loseHp(player, 1, "honor_ol_ex__lihuo")
    end
  end,
}
local ol_ex__chunlao = fk.CreateTriggerSkill{
  name = "honor_ol_ex__chunlao",
  anim_type = "support",
  derived_piles = "honor_ol_ex__chengpu_chun",
  events = {fk.AfterCardsMove, fk.AskForPeaches, fk.HpLost},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.AfterCardsMove then
        local cards = {}
        local room = player.room
        for _, move in ipairs(data) do
          if move.toArea == Card.DiscardPile then
            if move.moveReason == fk.ReasonDiscard and move.from and
              (move.from == player.id or move.from == player:getNextAlive().id or move.from == player:getLastAlive().id) then
              for _, info in ipairs(move.moveInfo) do
                if Fk:getCardById(info.cardId).trueName == "slash" and table.contains(room.discard_pile, info.cardId) then
                  table.insertIfNeed(cards, info.cardId)
                end
              end
            end
          end
        end
        cards = U.moveCardsHoldingAreaCheck(room, cards)
        if #cards > 0 then
          self.cost_data = cards
          return true
        end
      elseif event == fk.AskForPeaches then
        return target.dying and #player:getPile("honor_ol_ex__chengpu_chun") > 0
      else
        return #player:getPile("honor_ol_ex__chengpu_chun") > 1
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.AfterCardsMove then
      return true
    elseif event == fk.AskForPeaches then
      local n = 1
      local cards = player.room:askForCard(player, n, n, false, self.name, true, ".|.|.|honor_ol_ex__chengpu_chun|.|.",
        "#honor_ol_ex__chunlao-invoke::"..target.id..":"..n, "honor_ol_ex__chengpu_chun")
      if #cards > 0 then
        self.cost_data = cards
        return true
      end
    else
      local cids = player.room:askForCard(player, 2, 2, false, self.name, true, ".|.|.|honor_ol_ex__chengpu_chun", "#honor_ol_ex__chunlao-prey", "honor_ol_ex__chengpu_chun")
      if #cids == 2 then
        self.cost_data = cids
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardsMove then
      player:addToPile("honor_ol_ex__chengpu_chun", self.cost_data, true, self.name, player.id)
    elseif event == fk.AskForPeaches then
      room:moveCardTo(self.cost_data, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name, nil, true, player.id)
      if not target.dead then
        local card = Fk:cloneCard("analeptic")
        card.skillName = self.name
        if not target:prohibitUse(Fk:cloneCard("analeptic")) and not target:isProhibited(target, Fk:cloneCard("analeptic")) then
          room:useCard({
            card = Fk:cloneCard("analeptic"),
            from = target.id,
            tos = {{target.id}},
            extra_data = {
              analepticRecover = true
            },
          })
        end
      end
    else
      room:obtainCard(player, self.cost_data, true, fk.ReasonJustMove, player.id, self.name)
    end
  end,
}
ol_ex__lihuo:addRelatedSkill(ol_ex__lihuo_delay)
chengpu:addSkill(ol_ex__lihuo)
chengpu:addSkill(ol_ex__chunlao)
Fk:loadTranslationTable{
  ["honor_ol_ex__chengpu"] = "界程普",
  ["#honor_ol_ex__chengpu"] = "三朝虎臣",
  --["designer:ol_ex__chengpu"] = "",
  --["illustrator:ol_ex__chengpu"] = "",
  ["honor_ol_ex__lihuo"] = "疬火",
  [":honor_ol_ex__lihuo"] = "你使用非火【杀】可以改为火【杀】，此牌结算后，若造成了伤害，你弃置一张牌或失去1点体力。你使用火【杀】时可以增加一个目标。",
  ["honor_ol_ex__chunlao"] = "醇醪",
  [":honor_ol_ex__chunlao"] = "你或你相邻角色的【杀】因弃置进入弃牌堆后，将之置为“醇”。当一名角色处于濒死状态时，你可以将一张“醇”置入弃牌堆，"..
  "视为该角色使用一张【酒】。一名角色失去体力后，你可以获得两张“醇”。",
  ["#honor_ol_ex__lihuo-invoke"] = "疬火：是否将%arg改为火【杀】？",
  ["#honor_ol_ex__lihuo-discard"] = "疬火：弃置一张牌，否则你失去1点体力",
  ["#honor_ol_ex__lihuo_delay"] = "疬火",
  ["honor_ol_ex__chengpu_chun"] = "醇",
  ["#honor_ol_ex__chunlao-invoke"] = "醇醪：你可以将%arg张“醇”置入弃牌堆，视为 %dest 使用一张【酒】",
  ["#honor_ol_ex__chunlao-prey"] = "醇醪：你可以获得至多两张“醇”",
}

local zhugezhan = General(extension, "honor__zhugezhan", "shu", 3)
local zuilun = fk.CreateActiveSkill{
  name = "honor_zuilun",
  anim_type = "control",
  target_num = 1,
  target_filter = function (self, to_select, selected, selected_cards, card, extra_data)
    return #selected == 0 and to_select ~= Self.id and ((Self:getMark("honor_zuilun_hand-phase") == 0 and #Fk:currentRoom():getPlayerById(to_select):getCardIds("h") > 0)
     or (Self:getMark("honor_zuilun_equip-phase") == 0 and #Fk:currentRoom():getPlayerById(to_select):getCardIds("e") > 0))
  end,
  card_filter = Util.FalseFunc,
  can_use = function (self, player, card, extra_data)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < 2
  end,
  on_use = function (self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local area = ""
    if player:getMark("honor_zuilun_hand-phase") == 0 then
      area = area .. "h"
    end
    if player:getMark("honor_zuilun_equip-phase") == 0 then
      area = area .. "e"
    end
    if area ~= "" then
      local c = room:askForCardChosen(player, target, area, self.name, "#honor_zuilun-choose")
      if c then
        local fromArea = room:getCardArea(c)
        room:obtainCard(player, c, false, fk.ReasonPrey, player.id, self.name)
        if not player.dead then
          if fromArea == Card.PlayerHand then
            room:setPlayerMark(player, "honor_zuilun_hand-phase", 1)
          elseif fromArea == Card.PlayerEquip then
            room:setPlayerMark(player, "honor_zuilun_equip-phase", 1)
          end
        end
        if not target.dead then
          target:drawCards(1, self.name)
        end
      end
    end
  end
}
local fuyin = fk.CreateProhibitSkill{
  name = "honor_fuyin",
  frequency = Skill.Compulsory,
  is_prohibited = function(self, from, to, card)
    if to:hasSkill(self) then
      return not to:getEquipment(Card.SubtypeArmor) and #from:getCardIds("h") >=  #to:getCardIds("h") and table.contains({"slash", "duel", "fire_attack"}, card.trueName)
    end
  end,
}
zhugezhan:addSkill(zuilun)
zhugezhan:addSkill(fuyin)
Fk:loadTranslationTable{
  ["honor__zhugezhan"] = "诸葛瞻",
  ["#honor__zhugezhan"] = "临难死义",
  ["cv:honor__zhugezhan"] = "漠桀",
  ["illustrator:honor__zhugezhan"] = "zoo",
  ["honor_zuilun"] = "罪论",
  [":honor_zuilun"] = "出牌阶段手牌区和装备区各限一次，你可以获得一名其他角色的一张牌，然后该角色摸一张牌。",
  ["honor_fuyin"] = "父荫",
  [":honor_fuyin"] = "锁定技，若你的装备区里没有防具牌，手牌数大于等于你的其他角色不能使用【杀】、【决斗】或【火攻】指定你为目标。",
  ["#honor_zuilun-choose"] = "罪论：选择一张牌获得",

  ["$honor_zuilun1"] = "吾有三罪，未能除黄皓、制伯约、守国土。",
  ["$honor_zuilun2"] = "唉，数罪当论，吾愧对先帝恩惠。",
  ["$honor_fuyin1"] = "得父荫庇，平步青云。",
  ["$honor_fuyin2"] = "吾自幼心怀父诫，方不愧父亲荫庇。",
  ["~honor__zhugezhan"] = "临难而死义，无愧先父。",
}

local lukai = General(extension, "honor__lukai", "wu", 4)
local bushil = fk.CreateTriggerSkill{
  name = "honor_bushil",
  mute = true,
  events = {fk.CardUseFinished, fk.CardRespondFinished, fk.TargetConfirmed, fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == fk.CardUseFinished or event == fk.CardRespondFinished then
        return player:getMark("honor_bushil2") == "log_"..data.card:getSuitString()
      elseif event == fk.TargetConfirmed then
        return data.card.type ~= Card.TypeEquip and player:getMark("honor_bushil3") == "log_"..data.card:getSuitString() and not player:isKongcheng()
      elseif event == fk.EventPhaseStart then
        return player.phase == Player.Start or player.phase == Player.Finish
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseStart and player.phase == Player.Start then
      return player.room:askForSkillInvoke(player, self.name, nil, "#honor_bushil-invoke")
    elseif event == fk.TargetConfirmed then
      return true
      --[[local card = player.room:askForDiscard(player, 1, 1, false, self.name, true, ".", "#honor_bushil-discard:::"..data.card:toLogString(), true)
      if #card > 0 then
        self.cost_data = card
        return true
      end]]
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name)
    if event == fk.EventPhaseStart and player.phase == Player.Start then
      room:notifySkillInvoked(player, self.name, "special")
      local suits = {"log_spade", "log_heart", "log_club", "log_diamond"}
      for i = 1, 4, 1 do
        local choices = table.map(suits, Util.TranslateMapper)
        local choice = room:askForChoice(player, choices, self.name, "#honor_bushil"..i.."-choice")
        local str = suits[table.indexOf(choices, choice)]
        table.removeOne(suits, str)
        room:setPlayerMark(player, "honor_bushil"..i, str)
        room:setPlayerMark(player, "@honor_bushil", string.format("%s-%s-%s-%s",
        Fk:translate(player:getMark("honor_bushil1")),
        Fk:translate(player:getMark("honor_bushil2")),
        Fk:translate(player:getMark("honor_bushil3")),
        Fk:translate(player:getMark("honor_bushil4"))))
      end
    elseif event == fk.CardUseFinished or event == fk.CardRespondFinished then
      room:notifySkillInvoked(player, self.name, "drawcard")
      player:drawCards(2, self.name)
    elseif event == fk.TargetConfirmed then
      room:notifySkillInvoked(player, self.name, "defensive")
      local card = room:getCardsFromPileByRule(".|.|"..string.sub(player:getMark("honor_bushil4"), 5))
      if #card > 0 then
        room:moveCards({
          ids = card,
          to = player.id,
          toArea = Card.PlayerHand,
          moveReason = fk.ReasonJustMove,
          proposer = player.id,
          skillName = self.name,
        })
      end
      --[[
      room:throwCard(self.cost_data, self.name, player, player)
      if data.card.sub_type == Card.SubtypeDelayedTrick then
        AimGroup:cancelTarget(data, player.id)
      else
        table.insertIfNeed(data.nullifiedTargets, player.id)
      end]]
    elseif event == fk.EventPhaseStart and player.phase == Player.Finish then
      room:notifySkillInvoked(player, self.name, "drawcard")
      local card = room:getCardsFromPileByRule(".|.|"..string.sub(player:getMark("honor_bushil4"), 5))
      if #card > 0 then
        room:moveCards({
          ids = card,
          to = player.id,
          toArea = Card.PlayerHand,
          moveReason = fk.ReasonJustMove,
          proposer = player.id,
          skillName = self.name,
        })
      end
    end
  end,

  refresh_events = {fk.PreCardUse, fk.EventAcquireSkill, fk.EventLoseSkill},
  can_refresh = function(self, event, target, player, data)
    if event == fk.PreCardUse then
      return player:hasSkill(self) and player == target and player:getMark("honor_bushil1") == "log_"..data.card:getSuitString()
    else
      return target == player and data == self
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.PreCardUse then
      data.extraUse = true
    elseif event == fk.EventAcquireSkill then
      room:setPlayerMark(player, "honor_bushil1", "log_spade")
      room:setPlayerMark(player, "honor_bushil2", "log_heart")
      room:setPlayerMark(player, "honor_bushil3", "log_club")
      room:setPlayerMark(player, "honor_bushil4", "log_diamond")
      room:setPlayerMark(player, "@honor_bushil", string.format("%s-%s-%s-%s",
      Fk:translate(player:getMark("honor_bushil1")),
      Fk:translate(player:getMark("honor_bushil2")),
      Fk:translate(player:getMark("honor_bushil3")),
      Fk:translate(player:getMark("honor_bushil4"))))
    else
      for _, mark in ipairs({"honor_bushil1", "honor_bushil2", "honor_bushil3", "honor_bushil4", "@honor_bushil"}) do
        room:setPlayerMark(player, mark, 0)
      end
    end
  end,
}
local bushil_targetmod = fk.CreateTargetModSkill{
  name = "#honor_bushil_targetmod",
  bypass_times = function(self, player, skill, scope, card)
    return player:hasSkill(bushil) and player:getMark("honor_bushil1") == "log_"..card:getSuitString()
  end,
}
local zhongzhuang = fk.CreateTriggerSkill{
  name = "honor_zhongzhuang",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card and
      (player:getAttackRange() < 3 or (player:getAttackRange() > 3 and data.damage > 1))
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player:getAttackRange() < 3 then
      data.damage = data.damage + 1
      player:broadcastSkillInvoke(self.name, 1)
      room:notifySkillInvoked(player, self.name, "offensive")
    elseif player:getAttackRange() > 3 then
      data.damage = 1
      player:broadcastSkillInvoke(self.name, 2)
      room:notifySkillInvoked(player, self.name, "negative")
    end
  end,
}
bushil:addRelatedSkill(bushil_targetmod)
lukai:addSkill(bushil)
lukai:addSkill(zhongzhuang)
Fk:loadTranslationTable{
  ["honor__lukai"] = "陆凯",
  ["#honor__lukai"] = "青辞宰辅",
  ["designer:honor__lukai"] = "GT",
  ["illustrator:honor__lukai"] = "游漫美绘",

  ["honor_bushil"] = "卜筮",
  [":honor_bushil"] = "你使用♠牌无次数限制；<br>你使用或打出<font color='red'>♥</font>牌后，摸两张牌；<br>当你成为♣牌的目标后，"..
  "或结束阶段，你获得一张<font color='red'>♦</font>牌。<br>准备阶段，你可以将以上四种花色重新分配。",
  ["honor_zhongzhuang"] = "忠壮",
  [":honor_zhongzhuang"] = "锁定技，你造成伤害时，若你的攻击范围小于3，则此伤害+1；若你的攻击范围大于3，则此伤害改为1。",
  ["@honor_bushil"] = "卜筮",
  ["#honor_bushil-invoke"] = "卜筮：是否重新分配“卜筮”的花色？",
  --["#honor_bushil-discard"] = "卜筮：你可以弃置一张手牌令%arg对你无效",
  ["#honor_bushil1-choice"] = "卜筮：使用此花色牌无次数限制",
  ["#honor_bushil2-choice"] = "卜筮：使用或打出此花色牌后摸两张牌",
  ["#honor_bushil3-choice"] = "卜筮：成为此花色牌目标后或结束阶段，你获得一张未选花色的牌",

  ["$honor_bushil1"] = "论演玄意，以筮辄验。",
  ["$honor_bushil2"] = "手不释书，好研经卷。",
  ["$honor_zhongzhuang1"] = "秽尘天听，卿有不测之祸！",
  ["$honor_zhongzhuang2"] = "倾乱国政，安得寿终正寝？",
  ["~honor__lukai"] = "不听忠言，国将亡矣……",
}

local zhanghua = General(extension, "honor__zhanghua", "jin", 3)
zhanghua:addSkill("bihun")
zhanghua:addSkill("chuanwu")
zhanghua:addSkill("jianhe")
Fk:loadTranslationTable{
  ["honor__zhanghua"] = "张华",
  ["#honor__zhanghua"] = "双剑化龙",
  ["designer:honor__zhanghua"] = "玄蝶既白",
  ["illustrator:honor__zhanghua"] = "匠人绘",
  ["cv:honor__zhanghua"] = "苏至豪",

  ["~honor__zhanghua"] = "桑化为柏，此非不祥乎？",
}

return extension